4 This is a dump ground to make Lock Tree work without the rest of TokuDB.
9 #include "ft/ft-status.h"
10 #include "portability/memory.h"
13 // portability/os_malloc.cc
15 void toku_free(void *p
) { free(p
); }
17 void *toku_xmalloc(size_t size
) { return malloc(size
); }
19 void *toku_xrealloc(void *v
, size_t size
) { return realloc(v
, size
); }
21 void *toku_xmemdup(const void *v
, size_t len
) {
22 void *p
= toku_xmalloc(len
);
27 // TODO: what are the X-functions? Xcalloc, Xrealloc?
28 void *toku_xcalloc(size_t nmemb
, size_t size
) { return calloc(nmemb
, size
); }
33 toku_instr_key lock_request_m_wait_cond_key
;
34 toku_instr_key manager_m_escalator_done_key
;
35 toku_instr_key locktree_request_info_mutex_key
;
36 toku_instr_key locktree_request_info_retry_mutex_key
;
37 toku_instr_key locktree_request_info_retry_cv_key
;
39 toku_instr_key treenode_mutex_key
;
40 toku_instr_key manager_mutex_key
;
41 toku_instr_key manager_escalation_mutex_key
;
42 toku_instr_key manager_escalator_mutex_key
;
44 // portability/memory.cc
45 size_t toku_memory_footprint(void *, size_t touched
) { return touched
; }
48 // PORT2: note: the @c parameter to TOKUFT_STATUS_INIT must not start with
50 LTM_STATUS_S ltm_status
;
51 void LTM_STATUS_S::init() {
52 if (m_initialized
) return;
53 #define LTM_STATUS_INIT(k, c, t, l) \
54 TOKUFT_STATUS_INIT((*this), k, c, t, "locktree: " l, \
55 TOKU_ENGINE_STATUS | TOKU_GLOBAL_STATUS)
56 LTM_STATUS_INIT(LTM_SIZE_CURRENT
, LOCKTREE_MEMORY_SIZE
, STATUS_UINT64
,
58 LTM_STATUS_INIT(LTM_SIZE_LIMIT
, LOCKTREE_MEMORY_SIZE_LIMIT
, STATUS_UINT64
,
60 LTM_STATUS_INIT(LTM_ESCALATION_COUNT
, LOCKTREE_ESCALATION_NUM
, STATUS_UINT64
,
61 "number of times lock escalation ran");
62 LTM_STATUS_INIT(LTM_ESCALATION_TIME
, LOCKTREE_ESCALATION_SECONDS
,
63 STATUS_TOKUTIME
, "time spent running escalation (seconds)");
64 LTM_STATUS_INIT(LTM_ESCALATION_LATEST_RESULT
,
65 LOCKTREE_LATEST_POST_ESCALATION_MEMORY_SIZE
, STATUS_UINT64
,
66 "latest post-escalation memory size");
67 LTM_STATUS_INIT(LTM_NUM_LOCKTREES
, LOCKTREE_OPEN_CURRENT
, STATUS_UINT64
,
68 "number of locktrees open now");
69 LTM_STATUS_INIT(LTM_LOCK_REQUESTS_PENDING
, LOCKTREE_PENDING_LOCK_REQUESTS
,
70 STATUS_UINT64
, "number of pending lock requests");
71 LTM_STATUS_INIT(LTM_STO_NUM_ELIGIBLE
, LOCKTREE_STO_ELIGIBLE_NUM
,
72 STATUS_UINT64
, "number of locktrees eligible for the STO");
73 LTM_STATUS_INIT(LTM_STO_END_EARLY_COUNT
, LOCKTREE_STO_ENDED_NUM
,
75 "number of times a locktree ended the STO early");
76 LTM_STATUS_INIT(LTM_STO_END_EARLY_TIME
, LOCKTREE_STO_ENDED_SECONDS
,
77 STATUS_TOKUTIME
, "time spent ending the STO early (seconds)");
78 LTM_STATUS_INIT(LTM_WAIT_COUNT
, LOCKTREE_WAIT_COUNT
, STATUS_UINT64
,
79 "number of wait locks");
80 LTM_STATUS_INIT(LTM_WAIT_TIME
, LOCKTREE_WAIT_TIME
, STATUS_UINT64
,
81 "time waiting for locks");
82 LTM_STATUS_INIT(LTM_LONG_WAIT_COUNT
, LOCKTREE_LONG_WAIT_COUNT
, STATUS_UINT64
,
83 "number of long wait locks");
84 LTM_STATUS_INIT(LTM_LONG_WAIT_TIME
, LOCKTREE_LONG_WAIT_TIME
, STATUS_UINT64
,
85 "long time waiting for locks");
86 LTM_STATUS_INIT(LTM_TIMEOUT_COUNT
, LOCKTREE_TIMEOUT_COUNT
, STATUS_UINT64
,
87 "number of lock timeouts");
88 LTM_STATUS_INIT(LTM_WAIT_ESCALATION_COUNT
, LOCKTREE_WAIT_ESCALATION_COUNT
,
89 STATUS_UINT64
, "number of waits on lock escalation");
90 LTM_STATUS_INIT(LTM_WAIT_ESCALATION_TIME
, LOCKTREE_WAIT_ESCALATION_TIME
,
91 STATUS_UINT64
, "time waiting on lock escalation");
92 LTM_STATUS_INIT(LTM_LONG_WAIT_ESCALATION_COUNT
,
93 LOCKTREE_LONG_WAIT_ESCALATION_COUNT
, STATUS_UINT64
,
94 "number of long waits on lock escalation");
95 LTM_STATUS_INIT(LTM_LONG_WAIT_ESCALATION_TIME
,
96 LOCKTREE_LONG_WAIT_ESCALATION_TIME
, STATUS_UINT64
,
97 "long time waiting on lock escalation");
100 #undef LTM_STATUS_INIT
102 void LTM_STATUS_S::destroy() {
103 if (!m_initialized
) return;
104 for (int i
= 0; i
< LTM_STATUS_NUM_ROWS
; ++i
) {
105 if (status
[i
].type
== STATUS_PARCOUNT
) {
106 // PORT: TODO?? destroy_partitioned_counter(status[i].value.parcount);
111 int toku_keycompare(const void *key1
, size_t key1len
, const void *key2
,
113 size_t comparelen
= key1len
< key2len
? key1len
: key2len
;
114 int c
= memcmp(key1
, key2
, comparelen
);
115 if (__builtin_expect(c
!= 0, 1)) {
118 if (key1len
< key2len
) {
120 } else if (key1len
> key2len
) {
128 int toku_builtin_compare_fun(const DBT
*a
, const DBT
*b
) {
129 return toku_keycompare(a
->data
, a
->size
, b
->data
, b
->size
);
132 #endif // ROCKSDB_LITE