Jazz 1.26.+
Loading...
Searching...
No Matches
container.h
1/* Jazz (c) 2018-2026 kaalam.ai (The Authors of Jazz), using (under the same license):
2
3 1. Biomodelling - The AATBlockQueue class (c) Jacques BasaldĂșa, 2009-2012 licensed
4 exclusively for the use in the Jazz server software.
5
6 Copyright 2009-2012 Jacques BasaldĂșa
7
8 2. BBVA - Jazz: A lightweight analytical web server for data-driven applications.
9
10 Copyright 2016-2017 Banco Bilbao Vizcaya Argentaria, S.A.
11
12 This product includes software developed at
13
14 BBVA (https://www.bbva.com/)
15
16 3. LMDB, Copyright 2011-2017 Howard Chu, Symas Corp. All rights reserved.
17
18 Licensed under http://www.OpenLDAP.org/license.html
19
20
21 Licensed under the Apache License, Version 2.0 (the "License");
22 you may not use this file except in compliance with the License.
23 You may obtain a copy of the License at
24
25 http://www.apache.org/licenses/LICENSE-2.0
26
27 Unless required by applicable law or agreed to in writing, software
28 distributed under the License is distributed on an "AS IS" BASIS,
29 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 See the License for the specific language governing permissions and
31 limitations under the License.
32*/
33
34
35#include <map>
36#include <atomic>
37#include <thread>
38#include <regex>
39
40
41#include "src/jazz_elements/tuple.h"
42
43#ifdef CATCH_TEST
44#ifndef INCLUDED_JAZZ_CATCH2
45#define INCLUDED_JAZZ_CATCH2
46
47#include "src/catch2/catch.hpp"
48
49#endif
50#endif
51
52
53#ifndef INCLUDED_JAZZ_ELEMENTS_CONTAINER
54#define INCLUDED_JAZZ_ELEMENTS_CONTAINER
55
56namespace jazz_elements
57{
58
60#define MAX_SIZE_OF_CELL_AS_TEXT 48
61
63#define NA_AS_TEXT {"NA\0"}
64#define LENGTH_NA_AS_TEXT 2
65
67#define PARSE_ERROR_UNEXPECTED_EOF 101
68#define PARSE_ERROR_UNEXPECTED_CHAR 102
69#define PARSE_ERROR_ITEM_NAME 103
70#define PARSE_ERROR_ITEM_NAME_MISMATCH 104
71#define PARSE_ERROR_TENSOR_EXPLORATION 105
72
73#define PARSE_ERROR_KIND_EXPLORATION 106
74#define PARSE_ERROR_TOO_MANY_ITEMS 107
75#define PARSE_ERROR_EXPECTED_EOF 108
76#define PARSE_ERROR_TENSOR_FILLING 109
77#define PARSE_ERROR_TEXT_FILLING 110
78
80#define FILL_NEW_DONT_FILL 0
81#define FILL_NEW_WITH_ZERO 1
82#define FILL_NEW_WITH_NA 2
83#define FILL_WITH_TEXTFILE 3
84
85#define BUILD_TUPLE 1
86#define BUILD_KIND 2
87
89#define BLOCK_STATUS_READY 0
90#define BLOCK_STATUS_EMPTY 1
91#define BLOCK_STATUS_DESTROYED 2
92
94#define LOCK_NUM_RETRIES_BEFORE_YIELD 100
95
97#define LOCK_WEIGHT_OF_WRITE 46341
98
99// State based parser types:
100#define EIGHT_BIT_LONG 256
101#define MAX_TRANSITION_REGEX_LEN 32
102#define PSTATE_INVALID_CHAR 255
103
104// Writing modes for put(1): What to do is block exists:
105#define WRITE_ONLY_IF_EXISTS 0x01
106#define WRITE_ONLY_IF_NOT_EXISTS 0x02
107#define WRITE_ANY_RESTRICTION 0x03
108
109// Writing modes for put(2): What to write
110#define WRITE_AS_BASE_DEFAULT 0x00
111#define WRITE_AS_STRING 0x04
112#define WRITE_AS_CONTENT 0x08
113#define WRITE_AS_FULL_BLOCK 0x10
114#define WRITE_AS_ANY_WRITE 0x1C
115
116// Bit masks to trigger failures in tests when set in debug_trigger_failure
117#define TRIGGER_FAIL_TEXT_BLOCK 0x001
118#define TRIGGER_FAIL_FILL_TENSOR 0x002
119#define TRIGGER_FAIL_NEW_STRING_BLOCK 0x004
120#define TRIGGER_FAIL_NEW_BLOCK_ANY 0x008
121#define TRIGGER_FAIL_NEW_BLOCK_1 0x010
122#define TRIGGER_FAIL_NEW_BLOCK_2 0x020
123#define TRIGGER_FAIL_NEW_BLOCK_3 0x040
124#define TRIGGER_FAIL_NEW_BLOCK_4 0x080
125#define TRIGGER_FAIL_NEW_BLOCK_5 0x100
126#define TRIGGER_FAIL_NEW_BLOCK_6 0x200
127#define TRIGGER_FAIL_NEW_BLOCK_7 0x400
128#define TRIGGER_FAIL_NEW_BLOCK_8 0x800
129
130
134 unsigned char next[EIGHT_BIT_LONG];
135};
136
137
141 int from;
142 int to;
143 char rex[MAX_TRANSITION_REGEX_LEN];
144};
145
146
154void compile_next_state_LUT(ParseNextStateLUT lut[], int num_states, ParseStateTransition trans[]);
155
156
158typedef std::atomic<int32_t> Lock32;
159
160
162typedef class Container *pContainer;
163
164
166typedef std::map<String, pContainer> BaseNames;
167
168
186
187
188typedef struct ExtraLocator *pExtraLocator;
189
198struct Locator {
199 char base [SHORT_NAME_SIZE];
202
203 union {
206 };
207};
209
210
216
217
219typedef std::map<String, int> MapSI;
220
221
296class Container : public Service {
297
298 public:
299
300 Container(pLogger a_logger, pConfigFile a_config);
301 ~Container();
302
303 // Service API
304
305 StatusCode start ();
307
308 // .enter_read() .enter_write() .leave_read() .leave_write() .lock_container() .unlock_container()
309
310 void enter_read (pTransaction p_txn);
311 void enter_write(pTransaction p_txn, int total_times = 0);
312 void leave_read (pTransaction p_txn);
313 void leave_write(pTransaction p_txn);
314
315 // - Allocation: .new_block(), .destroy_transaction()
316
317 // 1. new_block(): Create a Tensor from raw data specifying everything from scratch.
319 int cell_type,
320 int *dim,
321 int fill_tensor = FILL_NEW_DONT_FILL,
322 int stringbuff_size = 0,
323 const char *p_text = nullptr,
324 char eol = '\n',
325 AttributeMap *att = nullptr);
326
327 // 2. new_block(): Create a Kind or Tuple from arrays of StaticBlockHeader, names, and, in the case of a tuple, Tensors.
329 int num_items,
330 StaticBlockHeader p_hea[],
331 Name p_names[],
332 pBlock p_block[],
333 AttributeMap *dims = nullptr,
334 AttributeMap *att = nullptr);
335
336 // 3. new_block(): Create a Tensor by selecting rows (filtering) from another Tensor.
338 pBlock p_from,
339 pBlock p_row_filter,
340 AttributeMap *att = nullptr);
341
342 // 4. new_block(): Create a Tensor by selecting an item from a Tuple.
344 pTuple p_from,
345 pChar name,
346 AttributeMap *att = nullptr);
347
348 // 5. new_block(): Create a Tensor, Kind or Tuple from a Text block kept as a Tensor of CELL_TYPE_BYTE of rank == 1.
350 pBlock p_from_text,
351 int cell_type,
352 pKind p_as_kind = nullptr,
353 AttributeMap *att = nullptr);
354
355 // 6. new_block(): Create a Tensor of CELL_TYPE_BYTE of rank == 1 with a text serialization of a Tensor, Kind or Tuple.
357 pBlock p_from_raw,
358 pChar p_fmt = nullptr,
359 bool ret_as_string = false,
360 AttributeMap *att = nullptr);
361
362 // 7. new_block(): Create an empty Index block.
364 int cell_type);
365
366 // 8. new_block(): Create a Tuple of (key:STRING[length],value:STRING[length]) with the content of an Index.
368 Index &index);
369
370 // Support for transactions creation/destruction
371
373 virtual void destroy_transaction (pTransaction &p_txn);
374
375 // Crud: .get(), .header(), .put(), .new_entity(), .remove(), .copy()
376
377 // The "easy" interface: Uses strings instead of locators. Is translated to the native interface by an as_locator() call.
378 virtual StatusCode get (pTransaction &p_txn,
379 pChar p_what);
380 virtual StatusCode get (pTransaction &p_txn,
381 pChar p_what,
382 pBlock p_row_filter);
383 virtual StatusCode get (pTransaction &p_txn,
384 pChar p_what,
385 pChar name);
386 virtual StatusCode locate (Locator &location,
387 pChar p_what);
388 virtual StatusCode header (StaticBlockHeader &hea,
389 pChar p_what);
390 virtual StatusCode header (pTransaction &p_txn,
391 pChar p_what);
392 virtual StatusCode put (pChar p_where,
393 pBlock p_block,
394 int mode = WRITE_AS_BASE_DEFAULT);
395 virtual StatusCode new_entity (pChar p_where);
396 virtual StatusCode remove (pChar p_where);
397 virtual StatusCode copy (pChar p_where,
398 pChar p_what);
399
400 // The function call interface: exec()/modify().
401 virtual StatusCode exec (pTransaction &p_txn,
402 Locator &function,
403 pTuple p_args);
404 virtual StatusCode modify (Locator &function,
405 pTuple p_args);
406
407 // The parser: This simple regex-based parser only needs override for Channels.
408 virtual StatusCode as_locator (Locator &result,
409 pChar p_what);
410
411 // The "native" interface: This is what really does the job and all Container descendants implement.
412 virtual StatusCode get (pTransaction &p_txn,
413 Locator &what);
414 virtual StatusCode get (pTransaction &p_txn,
415 Locator &what,
416 pBlock p_row_filter);
417 virtual StatusCode get (pTransaction &p_txn,
418 Locator &what,
419 pChar name);
420 virtual StatusCode locate (Locator &location,
421 Locator &what);
422 virtual StatusCode header (StaticBlockHeader &hea,
423 Locator &what);
424 virtual StatusCode header (pTransaction &p_txn,
425 Locator &what);
426 virtual StatusCode put (Locator &where,
427 pBlock p_block,
428 int mode = WRITE_AS_BASE_DEFAULT);
429 virtual StatusCode new_entity (Locator &where);
430 virtual StatusCode remove (Locator &where);
431 virtual StatusCode copy (Locator &where,
432 Locator &what);
433
448
449 if (p_txn->p_block->cell_type == CELL_TYPE_STRING)
450 if (p_txn->p_block->size == 1)
451 return SERVICE_NO_ERROR; // The block is already a string, we just leave it as it is.
452 else {
453 destroy_transaction(p_txn);
454
455 return SERVICE_ERROR_WRONG_TYPE;
456 }
457
458 if ((p_txn->p_block->cell_type != CELL_TYPE_BYTE) || (p_txn->p_block->rank != 1)) {
459 destroy_transaction(p_txn);
460
461 return SERVICE_ERROR_WRONG_TYPE;
462 }
463
464 pBlock p_blk = (pBlock) &p_txn->p_block->tensor.cell_byte[0];
465 int size = p_txn->p_block->size;
466
467 if (p_blk->total_bytes == size && p_blk->check_hash()) {
468 pBlock p_new = block_malloc(size);
469 if (p_new == nullptr) {
470 destroy_transaction(p_txn);
471
472 return SERVICE_ERROR_NO_MEM;
473 }
474 memcpy(p_new, p_blk, size);
475
476 alloc_bytes -= p_txn->p_block->total_bytes;
477 free(p_txn->p_block);
478
479 p_txn->p_block = p_new;
480
481 return SERVICE_NO_ERROR;
482 }
483
484 int block_len = strnlen((pChar) p_blk, size);
485 if (block_len < size - 1)
486 return SERVICE_NO_ERROR; // This is when the content is not a string, we just leave it as it is.
487
488 pTransaction p_aux;
489
490 reinterpret_cast <pChar>(p_blk)[size] = 0;
491
492 if (new_block(p_aux, CELL_TYPE_STRING, nullptr, FILL_WITH_TEXTFILE, 0, (pChar) p_blk, 0) != SERVICE_NO_ERROR) {
493 destroy_transaction(p_txn);
494
495 return SERVICE_ERROR_NO_MEM;
496 }
497 std::swap(p_txn->p_block, p_aux->p_block);
498
499 destroy_transaction(p_aux);
500
501 return SERVICE_NO_ERROR;
502 }
503
515 inline StatusCode unwrap_received(pTransaction &p_txn, pBlock p_maybe_block, int rec_size) {
516
517 if (rec_size > sizeof(BlockHeader) && p_maybe_block->total_bytes == rec_size && p_maybe_block->check_hash()) {
518 int ret = new_transaction(p_txn);
519
520 if (ret != SERVICE_NO_ERROR)
521 return ret;
522
523 pBlock p_new = block_malloc(rec_size);
524 if (p_new == nullptr) {
525 destroy_transaction(p_txn);
526
527 return SERVICE_ERROR_NO_MEM;
528 }
529 memcpy(p_new, p_maybe_block, rec_size);
530
531 p_txn->p_block = p_new;
532 p_txn->status = BLOCK_STATUS_READY;
533
534 return SERVICE_NO_ERROR;
535 }
536 if (strnlen((pChar) p_maybe_block, rec_size) != rec_size) {
537 int dim[MAX_TENSOR_RANK] = {rec_size, 0};
538 int ret = new_block(p_txn, CELL_TYPE_BYTE, dim, FILL_NEW_DONT_FILL);
539
540 if (ret == SERVICE_NO_ERROR)
541 memcpy(&p_txn->p_block->tensor.cell_byte[0], p_maybe_block, rec_size);
542
543 return ret;
544 }
545
546 return new_block(p_txn, CELL_TYPE_STRING, nullptr, FILL_WITH_TEXTFILE, 0, (pChar) p_maybe_block, 0);
547 }
548
549 // Support for container names in the BaseAPI .base_names()
550
551 virtual void base_names(BaseNames &base_names);
552
553#ifndef CATCH_TEST
554 protected:
555#endif
556
562 inline void* malloc(size_t size) {
563 if (alloc_bytes + size >= fail_alloc_bytes)
564 return nullptr;
565
566 void * ret = std::malloc(size);
567
568 if (ret != nullptr)
569 alloc_bytes += size;
570
571 return ret;
572 }
573
579 inline pBlock block_malloc(size_t size) {
580 pBlock p_blk = (pBlock) malloc(size);
581
582 if (p_blk != nullptr) {
583 p_blk->cell_type = 0;
584 p_blk->total_bytes = 0;
585 }
586
587 return p_blk;
588 }
589
596 inline void lock_container(int total_times = 0) {
597 int retry = 0;
598
599 while (true) {
600 int32_t lock = 0;
601 int32_t next = 1;
602 if (_lock_.compare_exchange_weak(lock, next))
603 return;
604
605 if (++retry > LOCK_NUM_RETRIES_BEFORE_YIELD) {
606 std::this_thread::yield();
607 retry = 0;
608 if (total_times) {
609 if (--total_times == 0)
610 return;
611 }
612 }
613 }
614 }
615
619 _lock_ = 0;
620 }
621
623
629 inline int from_hex(char c) {
630 return (c < 65) ? c - 48 : (c > 96) ? c - 87 : c - 55;
631 }
632
636 uint64_t alloc_bytes;
641 int log_error_level = LOG_ERROR;
642
643#ifndef CATCH_TEST
644 private:
645#endif
646
647 char HEX[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
648
650
658 inline int skip_space(pChar &p_in, int &num_bytes) {
659 while (num_bytes > 0) {
660 if (*p_in == 0)
661 return 0;
662
663 if (*p_in == ' ' || *p_in == '\t' || *p_in == '\n') {
664 p_in++;
665 num_bytes--;
666 } else
667 break;
668 }
669
670 return num_bytes;
671 }
672
680 inline char get_char(pChar &p_in, int &num_bytes) {
681 if (num_bytes < 1)
682 return 0;
683
684 num_bytes--;
685
686 return *(p_in++);
687 }
688
700 inline bool get_item_name(pChar &p_in,
701 int &num_bytes,
702 pChar p_out,
703 bool check_quotes = true,
704 bool check_colon = true,
705 bool dot_ended = false) {
706 if (skip_space(p_in, num_bytes) <= 1)
707 return false;
708
709 if (check_quotes && (get_char(p_in, num_bytes) != '"'))
710 return false;
711
712 char ch = get_char(p_in, num_bytes);
713
714 if (ch < 'A' || ch > 'z' || (ch > 'Z' && ch < 'a'))
715 return false;
716
717 *(p_out++) = ch;
718
719 for (int i = 1; i < NAME_LENGTH; i++) {
720 if (!check_quotes && (*p_in == ',' || *p_in == ']'))
721 break;
722
723 if (dot_ended && (*p_in == '.'))
724 break;
725
726 ch = get_char(p_in, num_bytes);
727
728 if ((check_quotes || dot_ended) && ch == '"')
729 break;
730
731 if (ch < '0' || ch > 'z' || (ch > '9' && ch < 'A') || (ch > 'Z' && ch < '_') || ch == 0x60)
732 return false;
733
734 *(p_out++) = ch;
735 }
736
737 *p_out = 0;
738
739 if (check_quotes && (ch != '"') && (get_char(p_in, num_bytes) != '"'))
740 return false;
741
742 if (check_colon) {
743 if (skip_space(p_in, num_bytes) <= 1)
744 return false;
745
746 if (get_char(p_in, num_bytes) != ':')
747 return false;
748 }
749
750 return true;
751 }
752
761 inline bool sscanf_int32(pChar &p_in, int &num_bytes, int &result) {
762 int r_len;
763
764 if (sscanf(p_in, "%i%n", &result, &r_len) > 0) {
765 p_in += r_len;
766 num_bytes -= r_len;
767
768 return num_bytes >= 0;
769 } else
770 return false;
771 }
772
781 inline bool push_int_cell(pChar cell, pChar &p_st, int * &p_out) {
782
783 if (p_st == cell) {
784 *(p_out++) = INTEGER_NA;
785
786 return true;
787 }
788 *p_st = 0;
789 p_st = cell;
790
791 if (sscanf(p_st, "%i", p_out) != 1)
792 return false;
793
794 p_out++;
795
796 return true;
797 }
798
807 inline bool push_int_cell(pChar cell, pChar &p_st, long long * &p_out) {
808
809 if (p_st == cell) {
810 *(p_out++) = LONG_INTEGER_NA;
811
812 return true;
813 }
814 *p_st = 0;
815 p_st = cell;
816
817 if (sscanf(p_st, "%lli", p_out) != 1)
818 return false;
819
820 p_out++;
821
822 return true;
823 }
824
833 inline bool push_bool_cell(pChar cell, pChar &p_st, bool * &p_out) {
834
835 if (p_st == cell) {
836 *reinterpret_cast<uint8_t *>(p_out++) = BYTE_BOOLEAN_NA;
837
838 return true;
839 }
840 *p_st = 0;
841 p_st = cell;
842
843 *(p_out++) = cell[0] == '1';
844
845 return true;
846 }
847
856 inline bool push_bool_cell(pChar cell, pChar &p_st, uint32_t * &p_out) {
857
858 if (p_st == cell) {
859 *(p_out++) = BOOLEAN_NA;
860
861 return true;
862 }
863 *p_st = 0;
864 p_st = cell;
865
866 *(p_out++) = cell[0] == '1';
867
868 return true;
869 }
870
879 inline bool push_real_cell(pChar cell, pChar &p_st, float * &p_out) {
880
881 if (p_st == cell) {
882 *(p_out++) = SINGLE_NA;
883
884 return true;
885 }
886 *p_st = 0;
887 p_st = cell;
888
889 if (sscanf(p_st, "%f", p_out) != 1)
890 return false;
891
892 p_out++;
893
894 return true;
895 }
896
905 inline bool push_real_cell(pChar cell, pChar &p_st, double * &p_out) {
906
907 if (p_st == cell) {
908 *(p_out++) = DOUBLE_NA;
909
910 return true;
911 }
912 *p_st = 0;
913 p_st = cell;
914
915 if (sscanf(p_st, "%lf", p_out) != 1)
916 return false;
917
918 p_out++;
919
920 return true;
921 }
922
932 inline bool push_time_cell(pChar cell, pChar &p_st, time_t * &p_out, pChar fmt) {
933
934 if (p_st == cell) {
935 *(p_out++) = TIME_POINT_NA;
936
937 return true;
938 }
939 *p_st = 0;
940 p_st = cell;
941
942 struct tm timeinfo = {0};
943
944 if (strptime(p_st, fmt, &timeinfo) == nullptr)
945 return false;
946
947 time_t xx = timegm(&timeinfo);
948 if (xx < 0) return false;
949
950 *(p_out++) = xx;
951
952 return true;
953 }
954
955 bool get_type_and_shape (pChar &p_in, int &num_bytes, ItemHeader *item_hea, MapSI &dims);
956 bool get_shape_and_size (pChar &p_in, int &num_bytes, int cell_type, ItemHeader *item_hea);
957 bool fill_text_buffer (pChar &p_in, int &num_bytes, pChar p_out, int num_cells, int is_NA[], int hasLN[]);
958 bool fill_tensor (pChar &p_in, int &num_bytes, pBlock p_block);
959
960 int new_text_block (pTransaction &p_txn, ItemHeader &item_hea, pChar &p_in, int &num_bytes, AttributeMap *att = nullptr);
961
962 int tensor_int_as_text (pBlock p_block, pChar p_dest, pChar p_fmt);
963 int tensor_bool_as_text (pBlock p_block, pChar p_dest);
964 int tensor_float_as_text (pBlock p_block, pChar p_dest, pChar p_fmt);
965 int tensor_string_as_text(pBlock p_block, pChar p_dest);
966 int tensor_time_as_text (pBlock p_block, pChar p_dest, pChar p_fmt);
967 int tuple_as_text (pTuple p_tuple, pChar p_dest, pChar p_fmt, int item_len[]);
968 int kind_as_text (pKind p_kind, pChar p_dest);
969
975 inline void opening_brackets(int rank, pChar &p_ret) {
976 for (int i = 0; i < rank; i++)
977 *(p_ret++) = '[';
978
979 *p_ret = 0;
980 }
981
991 inline pChar as_shape(int rank, int dim[], pChar p_ret, pKind p_kind) {
992 *(p_ret++) = '[';
993
994 for (int i = 0; i < rank; i++) {
995 int k = dim[i];
996 if (k < 0) {
997 char *p_dim_name = &p_kind->p_string_buffer()->buffer[-k];
998 strcpy(p_ret, p_dim_name);
999 p_ret += strlen(p_dim_name);
1000
1001 } else
1002 p_ret += sprintf(p_ret, "%i", k);
1003
1004 if (i < rank - 1) {
1005 *(p_ret++) = ',';
1006 *(p_ret++) = ' ';
1007 }
1008 }
1009
1010 *(p_ret++) = ']';
1011
1012 *p_ret = 0;
1013
1014 return p_ret;
1015 }
1016
1022 inline void as_hex(pChar &p_dest, uint8_t bl) {
1023 *(p_dest++) = '\\';
1024 *(p_dest++) = 'x';
1025 *(p_dest++) = HEX[bl >> 4];
1026 *(p_dest++) = HEX[bl & 0x0f];
1027 }
1028
1036 inline void separator(int rank_1, int dim[], int idx[], pChar &p_ret) {
1037 for (int i = rank_1; i >= 0; i--) {
1038 idx[i]++;
1039
1040 if (idx[i] == dim[i]) {
1041 idx[i] = 0;
1042 *(p_ret++) = ']';
1043 } else {
1044 *(p_ret++) = ',';
1045 *(p_ret++) = ' ';
1046
1047 for (int j = 0; j < rank_1 - i; j++)
1048 *(p_ret++) = '[';
1049
1050 break;
1051 }
1052 }
1053 *p_ret = 0;
1054 }
1055
1064 inline int separator_len(int rank_1, int dim[], int idx[]) {
1065 int ret = 0;
1066
1067 for (int i = rank_1; i >= 0; i--) {
1068 idx[i]++;
1069
1070 if (idx[i] == dim[i]) {
1071 idx[i] = 0;
1072 ret++;
1073 } else {
1074 ret += 2;
1075
1076 if (i == rank_1)
1077 return ret;
1078
1079 ret += rank_1 - i;
1080
1081 return ret;
1082 }
1083 }
1084 return ret;
1085 }
1086
1087#ifdef CATCH_TEST
1088 uint32_t debug_trigger_failure = 0;
1089#endif
1090
1091};
1092
1093// Instancing container, logger and config
1094// ---------------------------------------
1095
1098
1099#ifdef CATCH_TEST
1100
1101void compare_full_blocks(pBlock p_bl1, pBlock p_bl2, bool skip_value_check = false);
1102
1103extern Container CNT;
1104
1105#endif
1106
1107} // namespace jazz_elements
1108
1109#endif // ifndef INCLUDED_JAZZ_ELEMENTS_CONTAINER
pStringBuffer p_string_buffer()
Definition block.h:363
A configuration file as a key/value store.
Definition utils.h:218
Container: A Service to manage Jazz blocks. All Jazz blocks are managed by this or a descendant of th...
Definition container.h:296
StatusCode start()
Definition container.cpp:292
bool fill_text_buffer(pChar &p_in, int &num_bytes, pChar p_out, int num_cells, int is_NA[], int hasLN[])
Definition container.cpp:2676
int tensor_float_as_text(pBlock p_block, pChar p_dest, pChar p_fmt)
Definition container.cpp:3661
bool push_bool_cell(pChar cell, pChar &p_st, uint32_t *&p_out)
Definition container.h:856
int tuple_as_text(pTuple p_tuple, pChar p_dest, pChar p_fmt, int item_len[])
Definition container.cpp:4006
int new_text_block(pTransaction &p_txn, ItemHeader &item_hea, pChar &p_in, int &num_bytes, AttributeMap *att=nullptr)
Definition container.cpp:3326
void leave_write(pTransaction p_txn)
Definition container.cpp:434
bool get_shape_and_size(pChar &p_in, int &num_bytes, int cell_type, ItemHeader *item_hea)
Definition container.cpp:2511
char get_char(pChar &p_in, int &num_bytes)
Definition container.h:680
virtual StatusCode put(pChar p_where, pBlock p_block, int mode=WRITE_AS_BASE_DEFAULT)
Definition container.cpp:1965
int skip_space(pChar &p_in, int &num_bytes)
Definition container.h:658
StatusCode destroy_container()
Definition container.cpp:2376
bool push_real_cell(pChar cell, pChar &p_st, double *&p_out)
Definition container.h:905
int tensor_string_as_text(pBlock p_block, pChar p_dest)
Definition container.cpp:3780
virtual StatusCode as_locator(Locator &result, pChar p_what)
Definition container.cpp:2084
virtual StatusCode remove(pChar p_where)
Definition container.cpp:2003
char HEX[16]
Hex chars.
Definition container.h:647
void unlock_container()
Definition container.h:618
bool push_bool_cell(pChar cell, pChar &p_st, bool *&p_out)
Definition container.h:833
void opening_brackets(int rank, pChar &p_ret)
Definition container.h:975
int separator_len(int rank_1, int dim[], int idx[])
Definition container.h:1064
void enter_read(pTransaction p_txn)
Definition container.cpp:339
int kind_as_text(pKind p_kind, pChar p_dest)
Definition container.cpp:4125
int tensor_bool_as_text(pBlock p_block, pChar p_dest)
Definition container.cpp:3556
virtual StatusCode locate(Locator &location, pChar p_what)
Definition container.cpp:1895
virtual StatusCode new_transaction(pTransaction &p_txn)
Definition container.cpp:449
virtual StatusCode new_entity(pChar p_where)
Definition container.cpp:1984
pTransaction p_free
The free list of transactions.
Definition container.h:638
int log_error_level
The log level for Container and LMDB errors made a variable to silence it in tests.
Definition container.h:641
StatusCode unwrap_received(pTransaction &p_txn, pBlock p_maybe_block, int rec_size)
Definition container.h:515
int tensor_int_as_text(pBlock p_block, pChar p_dest, pChar p_fmt)
Definition container.cpp:3400
bool alloc_warning_issued
True if a warning was issued for over-allocation.
Definition container.h:639
bool sscanf_int32(pChar &p_in, int &num_bytes, int &result)
Definition container.h:761
StatusCode new_container()
Definition container.cpp:2334
Lock32 _lock_
A lock for the deque of transactions.
Definition container.h:640
virtual StatusCode exec(pTransaction &p_txn, Locator &function, pTuple p_args)
Definition container.cpp:2052
void separator(int rank_1, int dim[], int idx[], pChar &p_ret)
Definition container.h:1036
int max_transactions
The configured ONE_SHOT_MAX_TRANSACTIONS.
Definition container.h:633
bool push_real_cell(pChar cell, pChar &p_st, float *&p_out)
Definition container.h:879
uint64_t alloc_bytes
The current allocation in bytes.
Definition container.h:636
virtual StatusCode copy(pChar p_where, pChar p_what)
Definition container.cpp:2025
void enter_write(pTransaction p_txn, int total_times=0)
Definition container.cpp:369
void * malloc(size_t size)
Definition container.h:562
virtual void base_names(BaseNames &base_names)
Definition container.cpp:2327
virtual StatusCode get(pTransaction &p_txn, pChar p_what)
Definition container.cpp:1822
int from_hex(char c)
Definition container.h:629
bool push_int_cell(pChar cell, pChar &p_st, int *&p_out)
Definition container.h:781
pBlock block_malloc(size_t size)
Definition container.h:579
bool push_time_cell(pChar cell, pChar &p_st, time_t *&p_out, pChar fmt)
Definition container.h:932
bool fill_tensor(pChar &p_in, int &num_bytes, pBlock p_block)
Definition container.cpp:2824
StatusCode new_block(pTransaction &p_txn, int cell_type, int *dim, int fill_tensor=FILL_NEW_DONT_FILL, int stringbuff_size=0, const char *p_text=nullptr, char eol='\n', AttributeMap *att=nullptr)
Definition container.cpp:568
void as_hex(pChar &p_dest, uint8_t bl)
Definition container.h:1022
pTransaction p_buffer
The buffer for the transactions.
Definition container.h:637
bool push_int_cell(pChar cell, pChar &p_st, long long *&p_out)
Definition container.h:807
bool get_item_name(pChar &p_in, int &num_bytes, pChar p_out, bool check_quotes=true, bool check_colon=true, bool dot_ended=false)
Definition container.h:700
uint64_t fail_alloc_bytes
Taken from ONE_SHOT_ERROR_BLOCK_KBYTES.
Definition container.h:635
int tensor_time_as_text(pBlock p_block, pChar p_dest, pChar p_fmt)
Definition container.cpp:3934
pChar as_shape(int rank, int dim[], pChar p_ret, pKind p_kind)
Definition container.h:991
virtual StatusCode header(StaticBlockHeader &hea, pChar p_what)
Definition container.cpp:1916
bool get_type_and_shape(pChar &p_in, int &num_bytes, ItemHeader *item_hea, MapSI &dims)
Definition container.cpp:2407
void lock_container(int total_times=0)
Definition container.h:596
uint64_t warn_alloc_bytes
Taken from ONE_SHOT_WARN_BLOCK_KBYTES.
Definition container.h:634
void leave_read(pTransaction p_txn)
Definition container.cpp:414
virtual StatusCode modify(Locator &function, pTuple p_args)
Definition container.cpp:2069
StatusCode shut_down()
Definition container.cpp:325
StatusCode unwrap_received(pTransaction &p_txn)
Definition container.h:447
virtual void destroy_transaction(pTransaction &p_txn)
Definition container.cpp:488
Kind: A type definition for Jazz Blocks and Tuples.
Definition kind.h:96
A simple logger.
Definition utils.h:248
A Jazz Service is a globally instanced configurable object that may allocate RAM.
Definition utils.h:288
Tuple: A Jazz Block with multiple Tensors.
Definition tuple.h:94
The namespace for Jazz Utils, Blocks, Kinds, Tuples, Containers, etc.
Definition block.cpp:39
Logger LOGGER(CONFIG, "LOGGER_PATH")
The logger.
Definition container.h:1097
struct ExtraLocator * pExtraLocator
A pointer to an ExtraLocator.
Definition container.h:188
ConfigFile CONFIG(JAZZ_DEFAULT_CONFIG_PATH)
The configuration file.
Definition container.h:1096
Transaction * pTransaction
A pointer to a Transaction.
Definition container.h:185
Locator * pLocator
A pointer to a Locator.
Definition container.h:208
std::map< String, pContainer > BaseNames
A map of names for the containers (or structure engines like "map" or "tree" inside Volatile).
Definition container.h:166
StoredTransaction * pStoredTransaction
A pointer to a StoredTransaction.
Definition container.h:215
char * pChar
A pointer to a char buffer.
Definition types.h:189
class Block * pBlock
A (forward defined) pointer to a Block.
Definition block.h:66
char Name[NAME_SIZE]
A short identifier used in Blocks, Containers and API.
Definition types.h:187
void compile_next_state_LUT(ParseNextStateLUT lut[], int num_states, ParseStateTransition trans[])
Definition container.cpp:59
std::map< String, int > MapSI
An internal map for managing dimension parsing.
Definition container.h:219
std::atomic< int32_t > Lock32
An atomically increased (via fetch_add() and fetch_sub()) 32 bit signed integer to use as a lock.
Definition container.h:158
class Container * pContainer
A (forward defined) pointer to a Container.
Definition container.h:162
int StatusCode
Type returned by the Service API.
Definition utils.h:142
std::map< int, const char * > AttributeMap
An stdlib map to store all the attributes of a Block at the same time used by the some Block methods.
Definition block.h:63
std::map< String, String > Index
An Index kept in RAM by Volatile implemented as an stdlib map (string, string)
Definition types.h:243
Header for a Movable Block (Tensor, Kind or Tuple) or a Dynamic Block (Index)
Definition types.h:247
Header for an item (of a Kind or Tuple)
Definition types.h:202
Locator: A minimal structure to define the location of resources inside a Container.
Definition container.h:198
char base[SHORT_NAME_SIZE]
A Jazz node level unique name to locate a Container and possibly a type of service inside it.
Definition container.h:199
Name entity
Another abstraction inside node.container.base, like the name of a table in a database.
Definition container.h:200
Name key
A key identifying a block inside the entity.
Definition container.h:201
int attribute
Used by API to store the attribute.
Definition container.h:204
pExtraLocator p_extra
A pointer to extend this structure with Container specific data (like URLs, cookies,...
Definition container.h:205
A lookup table for all the possible values of a char mapped into an 8-bit state.
Definition container.h:133
unsigned char next[EIGHT_BIT_LONG]
The next state for each possible char.
Definition container.h:134
A way to build constants defining the transition from one state to the next via a regex.
Definition container.h:140
int from
The state to transition from.
Definition container.h:141
char rex[MAX_TRANSITION_REGEX_LEN]
The regex that, when matched, the transition applies.
Definition container.h:143
int to
The state to transition to.
Definition container.h:142
A Binary Compatible BlockHeader without Index (and therefore constructors/destructors)
Definition types.h:270
An internal (for Container) Transaction with pointers for a deque.
Definition container.h:212
StoredTransaction * p_next
A pointer to the next StoredTransaction.
Definition container.h:213
char buffer[]
The buffer where strings are stored starting with two zeroes for STRING_NA & STRING_EMPTY.
Definition types.h:292
Transaction: A wrapper over a Block that defines the communication of a block with a Container.
Definition container.h:176
pBlockHeader p_hea
A pointer to the Block (if status == BLOCK_STATUS_READY) for Index.
Definition container.h:179
Lock32 _lock_
An atomically updated int to lock the Transaction to support modifying the Block.
Definition container.h:181
int status
The status of the block transaction.
Definition container.h:182
pBlock p_block
A pointer to the Block (if status == BLOCK_STATUS_READY) for Tensor, Kind and Tuple.
Definition container.h:178
pContainer p_owner
A pointer to the Container instance serving API calls related to this block.
Definition container.h:183