1
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
8
COPYING CONDITIONS NOTICE:
10
This program is free software; you can redistribute it and/or modify
11
it under the terms of version 2 of the GNU General Public License as
12
published by the Free Software Foundation, and provided that the
13
following conditions are met:
15
* Redistributions of source code must retain this COPYING
16
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
17
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
18
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
21
* Redistributions in binary form must reproduce this COPYING
22
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
23
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
24
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
25
GRANT (below) in the documentation and/or other materials
26
provided with the distribution.
28
You should have received a copy of the GNU General Public License
29
along with this program; if not, write to the Free Software
30
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
35
TokuDB, Tokutek Fractal Tree Indexing Library.
36
Copyright (C) 2007-2013 Tokutek, Inc.
40
This program is distributed in the hope that it will be useful, but
41
WITHOUT ANY WARRANTY; without even the implied warranty of
42
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
43
General Public License for more details.
45
UNIVERSITY PATENT NOTICE:
47
The technology is licensed by the Massachusetts Institute of
48
Technology, Rutgers State University of New Jersey, and the Research
49
Foundation of State University of New York at Stony Brook under
50
United States of America Serial No. 11/760379 and to the patents
51
and/or patent applications resulting from it.
53
PATENT MARKING NOTICE:
55
This software is covered by US Patent No. 8,185,551.
56
This software is covered by US Patent No. 8,489,638.
60
"THIS IMPLEMENTATION" means the copyrightable works distributed by
61
Tokutek as part of the Fractal Tree project.
63
"PATENT CLAIMS" means the claims of patents that are owned or
64
licensable by Tokutek, both currently or in the future; and that in
65
the absence of this license would be infringed by THIS
66
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
68
"PATENT CHALLENGE" shall mean a challenge to the validity,
69
patentability, enforceability and/or non-infringement of any of the
70
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
72
Tokutek hereby grants to you, for the term and geographical scope of
73
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
74
irrevocable (except as stated in this section) patent license to
75
make, have made, use, offer to sell, sell, import, transfer, and
76
otherwise run, modify, and propagate the contents of THIS
77
IMPLEMENTATION, where such license applies only to the PATENT
78
CLAIMS. This grant does not include claims that would be infringed
79
only as a consequence of further modifications of THIS
80
IMPLEMENTATION. If you or your agent or licensee institute or order
81
or agree to the institution of patent litigation against any entity
82
(including a cross-claim or counterclaim in a lawsuit) alleging that
83
THIS IMPLEMENTATION constitutes direct or contributory patent
84
infringement, or inducement of patent infringement, then any rights
85
granted to you under this License shall terminate as of the date
86
such litigation is filed. If you or your agent or exclusive
87
licensee institute or order or agree to the institution of a PATENT
88
CHALLENGE, then Tokutek may terminate any rights granted to you
92
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
93
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
99
// Maintain a cache mapping from cachekeys to values (void*)
100
// Some of the keys can be pinned. Don't pin too many or for too long.
101
// If the cachetable is too full, it will call the flush_callback() function with the key, the value, and the otherargs
102
// and then remove the key-value pair from the cache.
103
// The callback won't be any of the currently pinned keys.
104
// Also when flushing an object, the cachetable drops all references to it,
105
// so you may need to free() it.
106
// Note: The cachetable should use a common pool of memory, flushing things across cachetables.
107
// (The first implementation doesn't)
108
// If you pin something twice, you must unpin it twice.
109
// table_size is the initial size of the cache table hash table (in number of entries)
110
// size limit is the upper bound of the sum of size of the entries in the cache table (total number of bytes)
112
typedef BLOCKNUM CACHEKEY;
114
void toku_set_cleaner_period (CACHETABLE ct, uint32_t new_period);
115
uint32_t toku_get_cleaner_period_unlocked (CACHETABLE ct);
116
void toku_set_cleaner_iterations (CACHETABLE ct, uint32_t new_iterations);
117
uint32_t toku_get_cleaner_iterations (CACHETABLE ct);
118
uint32_t toku_get_cleaner_iterations_unlocked (CACHETABLE ct);
120
// cachetable operations
122
// create and initialize a cache table
123
// size_limit is the upper limit on the size of the size of the values in the table
124
// pass 0 if you want the default
125
int toku_cachetable_create(CACHETABLE *result, long size_limit, LSN initial_lsn, TOKULOGGER);
127
// Create a new cachetable.
128
// Effects: a new cachetable is created and initialized.
129
// The cachetable pointer is stored into result.
130
// The sum of the sizes of the memory objects is set to size_limit, in whatever
131
// units make sense to the user of the cachetable.
132
// Returns: If success, returns 0 and result points to the new cachetable. Otherwise,
133
// returns an error number.
135
// Returns a pointer to the checkpointer within the given cachetable.
136
CHECKPOINTER toku_cachetable_get_checkpointer(CACHETABLE ct);
138
// What is the cachefile that goes with a particular filenum?
139
// During a transaction, we cannot reuse a filenum.
140
int toku_cachefile_of_filenum (CACHETABLE t, FILENUM filenum, CACHEFILE *cf);
142
// What is the cachefile that goes with a particular iname (relative to env)?
143
// During a transaction, we cannot reuse an iname.
144
int toku_cachefile_of_iname_in_env (CACHETABLE ct, const char *iname_in_env, CACHEFILE *cf);
146
// Get the iname (within the cwd) associated with the cachefile
147
// Return the filename
148
char *toku_cachefile_fname_in_cwd (CACHEFILE cf);
150
void toku_cachetable_begin_checkpoint (CHECKPOINTER cp, TOKULOGGER);
152
void toku_cachetable_end_checkpoint(CHECKPOINTER cp, TOKULOGGER logger,
153
void (*testcallback_f)(void*), void * testextra);
155
// Shuts down checkpoint thread
156
// Requires no locks be held that are taken by the checkpoint function
157
void toku_cachetable_minicron_shutdown(CACHETABLE ct);
159
// Close the cachetable.
160
// Effects: All of the memory objects are flushed to disk, and the cachetable is destroyed.
161
void toku_cachetable_close(CACHETABLE *ct);
163
// Open a file and bind the file to a new cachefile object. (For use by test programs only.)
164
int toku_cachetable_openf(CACHEFILE *,CACHETABLE, const char *fname_in_env, int flags, mode_t mode);
166
// Bind a file to a new cachefile object.
167
int toku_cachetable_openfd(CACHEFILE *,CACHETABLE, int fd,
168
const char *fname_relative_to_env);
169
int toku_cachetable_openfd_with_filenum (CACHEFILE *,CACHETABLE, int fd,
170
const char *fname_in_env,
171
FILENUM filenum, bool* was_open);
173
// reserve a unique filenum
174
FILENUM toku_cachetable_reserve_filenum(CACHETABLE ct);
176
// Effect: Reserve a fraction of the cachetable memory.
177
// Returns the amount reserved.
178
// To return the memory to the cachetable, call toku_cachetable_release_reserved_memory
179
// Requires 0<fraction<1.
180
uint64_t toku_cachetable_reserve_memory(CACHETABLE, double fraction, uint64_t upper_bound);
181
void toku_cachetable_release_reserved_memory(CACHETABLE, uint64_t);
183
// cachefile operations
185
// Does an fsync of a cachefile.
186
void toku_cachefile_fsync(CACHEFILE cf);
188
enum partial_eviction_cost {
189
PE_CHEAP=0, // running partial eviction is cheap, and can be done on the client thread
190
PE_EXPENSIVE=1, // running partial eviction is expensive, and should not be done on the client thread
193
// cachetable pair clean or dirty WRT external memory
194
enum cachetable_dirty {
195
CACHETABLE_CLEAN=0, // the cached object is clean WRT the cachefile
196
CACHETABLE_DIRTY=1, // the cached object is dirty WRT the cachefile
199
// The flush callback is called when a key value pair is being written to storage and possibly removed from the cachetable.
200
// When write_me is true, the value should be written to storage.
201
// When keep_me is false, the value should be freed.
202
// When for_checkpoint is true, this was a 'pending' write
203
// Returns: 0 if success, otherwise an error number.
204
// Can access fd (fd is protected by a readlock during call)
205
typedef void (*CACHETABLE_FLUSH_CALLBACK)(CACHEFILE, int fd, CACHEKEY key, void *value, void **disk_data, void *write_extraargs, PAIR_ATTR size, PAIR_ATTR* new_size, bool write_me, bool keep_me, bool for_checkpoint, bool is_clone);
207
// The fetch callback is called when a thread is attempting to get and pin a memory
208
// object and it is not in the cachetable.
209
// Returns: 0 if success, otherwise an error number. The address and size of the object
210
// associated with the key are returned.
211
// Can access fd (fd is protected by a readlock during call)
212
typedef int (*CACHETABLE_FETCH_CALLBACK)(CACHEFILE, PAIR p, int fd, CACHEKEY key, uint32_t fullhash, void **value_data, void **disk_data, PAIR_ATTR *sizep, int *dirtyp, void *read_extraargs);
214
// The cachetable calls the partial eviction estimate callback to determine if
215
// partial eviction is a cheap operation that may be called by on the client thread
216
// or whether partial eviction is expensive and should be done on a background (writer) thread.
217
// The callback conveys this information by setting cost to either PE_CHEAP or PE_EXPENSIVE.
218
// If cost is PE_EXPENSIVE, then the callback also sets bytes_freed_estimate
219
// to return an estimate of the number of bytes it will free
220
// so that the cachetable can estimate how much data is being evicted on background threads.
221
// If cost is PE_CHEAP, then the callback does not set bytes_freed_estimate.
222
typedef void (*CACHETABLE_PARTIAL_EVICTION_EST_CALLBACK)(void *ftnode_pv, void* disk_data, long* bytes_freed_estimate, enum partial_eviction_cost *cost, void *write_extraargs);
224
// The cachetable calls the partial eviction callback is to possibly try and partially evict pieces
225
// of the PAIR. The callback determines the strategy for what to evict. The callback may choose to free
226
// nothing, or may choose to free as much as possible. When the partial eviction callback is finished,
227
// it must call finalize with the new PAIR_ATTR and the given finalize_extra. After this point, the
228
// write lock will be released on the PAIR and it is no longer safe to operate on any of the passed arguments.
229
// This is useful for doing expensive cleanup work outside of the PAIR's write lock (such as destroying objects, etc)
231
// on entry, requires a write lock to be held on the PAIR in the cachetable while this function is called
232
// on exit, the finalize continuation is called
233
typedef int (*CACHETABLE_PARTIAL_EVICTION_CALLBACK)(void *ftnode_pv, PAIR_ATTR old_attr, void *write_extraargs,
234
void (*finalize)(PAIR_ATTR new_attr, void *extra), void *finalize_extra);
236
// The cachetable calls this function to determine if get_and_pin call requires a partial fetch. If this function returns true,
237
// then the cachetable will subsequently call CACHETABLE_PARTIAL_FETCH_CALLBACK to perform
238
// a partial fetch. If this function returns false, then the PAIR's value is returned to the caller as is.
240
// An alternative to having this callback is to always call CACHETABLE_PARTIAL_FETCH_CALLBACK, and let
241
// CACHETABLE_PARTIAL_FETCH_CALLBACK decide whether to do any partial fetching or not.
242
// There is no particular reason why this alternative was not chosen.
243
// Requires: a read lock to be held on the PAIR
244
typedef bool (*CACHETABLE_PARTIAL_FETCH_REQUIRED_CALLBACK)(void *ftnode_pv, void *read_extraargs);
246
// The cachetable calls the partial fetch callback when a thread needs to read or decompress a subset of a PAIR into memory.
247
// An example is needing to read a basement node into memory. Another example is decompressing an internal node's
248
// message buffer. The cachetable determines if a partial fetch is necessary by first calling CACHETABLE_PARTIAL_FETCH_REQUIRED_CALLBACK.
249
// The new PAIR_ATTR of the PAIR is returned in sizep
250
// Can access fd (fd is protected by a readlock during call)
251
// Returns: 0 if success, otherwise an error number.
252
typedef int (*CACHETABLE_PARTIAL_FETCH_CALLBACK)(void *value_data, void* disk_data, void *read_extraargs, int fd, PAIR_ATTR *sizep);
254
// The cachetable calls the put callback during a cachetable_put command to provide the opaque PAIR.
255
// The PAIR can then be used to later unpin the pair.
256
// Returns: 0 if success, otherwise an error number.
257
typedef void (*CACHETABLE_PUT_CALLBACK)(CACHEKEY key, void *value_data, PAIR p);
259
// TODO(leif) XXX TODO XXX
260
typedef int (*CACHETABLE_CLEANER_CALLBACK)(void *ftnode_pv, BLOCKNUM blocknum, uint32_t fullhash, void *write_extraargs);
262
typedef void (*CACHETABLE_CLONE_CALLBACK)(void* value_data, void** cloned_value_data, long* clone_size, PAIR_ATTR* new_attr, bool for_checkpoint, void* write_extraargs);
264
typedef void (*CACHETABLE_CHECKPOINT_COMPLETE_CALLBACK)(void *value_data);
267
CACHETABLE_FLUSH_CALLBACK flush_callback;
268
CACHETABLE_PARTIAL_EVICTION_EST_CALLBACK pe_est_callback;
269
CACHETABLE_PARTIAL_EVICTION_CALLBACK pe_callback;
270
CACHETABLE_CLEANER_CALLBACK cleaner_callback;
271
CACHETABLE_CLONE_CALLBACK clone_callback;
272
CACHETABLE_CHECKPOINT_COMPLETE_CALLBACK checkpoint_complete_callback;
273
void* write_extraargs; // parameter for flush_callback, pe_est_callback, pe_callback, and cleaner_callback
274
} CACHETABLE_WRITE_CALLBACK;
276
typedef void (*CACHETABLE_GET_KEY_AND_FULLHASH)(CACHEKEY* cachekey, uint32_t* fullhash, void* extra);
278
typedef void (*CACHETABLE_REMOVE_KEY)(CACHEKEY* cachekey, bool for_checkpoint, void* extra);
280
void toku_cachefile_set_userdata(CACHEFILE cf, void *userdata,
281
void (*log_fassociate_during_checkpoint)(CACHEFILE, void*),
282
void (*close_userdata)(CACHEFILE, int, void*, bool, LSN),
283
void (*free_userdata)(CACHEFILE, void*),
284
void (*checkpoint_userdata)(CACHEFILE, int, void*),
285
void (*begin_checkpoint_userdata)(LSN, void*),
286
void (*end_checkpoint_userdata)(CACHEFILE, int, void*),
287
void (*note_pin_by_checkpoint)(CACHEFILE, void*),
288
void (*note_unpin_by_checkpoint)(CACHEFILE, void*));
289
// Effect: Store some cachefile-specific user data. When the last reference to a cachefile is closed, we call close_userdata().
290
// Before starting a checkpoint, we call checkpoint_prepare_userdata().
291
// When the cachefile needs to be checkpointed, we call checkpoint_userdata().
292
// If userdata is already non-NULL, then we simply overwrite it.
294
void *toku_cachefile_get_userdata(CACHEFILE);
295
// Effect: Get the user data.
297
CACHETABLE toku_cachefile_get_cachetable(CACHEFILE cf);
298
// Effect: Get the cachetable.
300
void toku_cachetable_swap_pair_values(PAIR old_pair, PAIR new_pair);
301
// Effect: Swaps the value_data of old_pair and new_pair.
302
// Requires: both old_pair and new_pair to be pinned with write locks.
310
// put something into the cachetable and checkpoint dependent pairs
311
// if the checkpointing is necessary
312
void toku_cachetable_put_with_dep_pairs(
314
CACHETABLE_GET_KEY_AND_FULLHASH get_key_and_fullhash,
317
CACHETABLE_WRITE_CALLBACK write_callback,
318
void *get_key_and_fullhash_extra,
319
uint32_t num_dependent_pairs, // number of dependent pairs that we may need to checkpoint
320
PAIR* dependent_pairs,
321
enum cachetable_dirty* dependent_dirty, // array stating dirty/cleanness of dependent pairs
324
CACHETABLE_PUT_CALLBACK put_callback
327
// Put a memory object into the cachetable.
328
// Effects: Lookup the key in the cachetable. If the key is not in the cachetable,
329
// then insert the pair and pin it. Otherwise return an error. Some of the key
330
// value pairs may be evicted from the cachetable when the cachetable gets too big.
331
void toku_cachetable_put(CACHEFILE cf, CACHEKEY key, uint32_t fullhash,
332
void *value, PAIR_ATTR size,
333
CACHETABLE_WRITE_CALLBACK write_callback,
334
CACHETABLE_PUT_CALLBACK put_callback
337
// Get and pin the memory object of a PAIR, and write dependent pairs to disk
338
// if the dependent pairs are pending a checkpoint.
339
// Effects: If the memory object is in the cachetable, acquire a PAIR lock on it.
340
// Otherwise, fetch it from storage by calling the fetch callback. If the fetch
341
// succeeded, add the memory object to the cachetable with a PAIR lock on it.
342
// Before returning to the user, if the PAIR object being retrieved, or any of the
343
// dependent pairs passed in as parameters must be written to disk for checkpoint,
344
// then the required PAIRs are written to disk for checkpoint.
345
// KEY PROPERTY OF DEPENDENT PAIRS: They are already locked by the client
346
// Returns: 0 if the memory object is in memory, otherwise an error number.
347
int toku_cachetable_get_and_pin_with_dep_pairs (
353
CACHETABLE_WRITE_CALLBACK write_callback,
354
CACHETABLE_FETCH_CALLBACK fetch_callback,
355
CACHETABLE_PARTIAL_FETCH_REQUIRED_CALLBACK pf_req_callback,
356
CACHETABLE_PARTIAL_FETCH_CALLBACK pf_callback,
357
pair_lock_type lock_type,
358
void* read_extraargs, // parameter for fetch_callback, pf_req_callback, and pf_callback
359
uint32_t num_dependent_pairs, // number of dependent pairs that we may need to checkpoint
360
PAIR* dependent_pairs,
361
enum cachetable_dirty* dependent_dirty // array stating dirty/cleanness of dependent pairs
364
// Get and pin a memory object.
365
// Effects: If the memory object is in the cachetable acquire the PAIR lock on it.
366
// Otherwise, fetch it from storage by calling the fetch callback. If the fetch
367
// succeeded, add the memory object to the cachetable with a read lock on it.
368
// Returns: 0 if the memory object is in memory, otherwise an error number.
369
int toku_cachetable_get_and_pin (
375
CACHETABLE_WRITE_CALLBACK write_callback,
376
CACHETABLE_FETCH_CALLBACK fetch_callback,
377
CACHETABLE_PARTIAL_FETCH_REQUIRED_CALLBACK pf_req_callback,
378
CACHETABLE_PARTIAL_FETCH_CALLBACK pf_callback,
379
bool may_modify_value,
380
void* read_extraargs // parameter for fetch_callback, pf_req_callback, and pf_callback
383
// does partial fetch on a pinned pair
384
void toku_cachetable_pf_pinned_pair(
386
CACHETABLE_PARTIAL_FETCH_CALLBACK pf_callback,
387
void* read_extraargs,
395
void (*f)(void* extra);
400
// Effect: If the block is in the cachetable, then return it.
401
// Otherwise call the functions in unlockers, fetch the data (but don't pin it, since we'll just end up pinning it again later), and return TOKUDB_TRY_AGAIN.
402
int toku_cachetable_get_and_pin_nonblocking (
408
CACHETABLE_WRITE_CALLBACK write_callback,
409
CACHETABLE_FETCH_CALLBACK fetch_callback,
410
CACHETABLE_PARTIAL_FETCH_REQUIRED_CALLBACK pf_req_callback,
411
CACHETABLE_PARTIAL_FETCH_CALLBACK pf_callback,
412
pair_lock_type lock_type,
413
void *read_extraargs, // parameter for fetch_callback, pf_req_callback, and pf_callback
417
int toku_cachetable_maybe_get_and_pin (CACHEFILE, CACHEKEY, uint32_t /*fullhash*/, pair_lock_type, void**);
418
// Effect: Maybe get and pin a memory object.
419
// This function is similar to the get_and_pin function except that it
420
// will not attempt to fetch a memory object that is not in the cachetable or requires any kind of blocking to get it.
421
// Returns: If the the item is already in memory, then return 0 and store it in the
422
// void**. If the item is not in memory, then return a nonzero error number.
424
int toku_cachetable_maybe_get_and_pin_clean (CACHEFILE, CACHEKEY, uint32_t /*fullhash*/, pair_lock_type, void**);
425
// Effect: Like maybe get and pin, but may pin a clean pair.
427
int toku_cachetable_unpin(CACHEFILE, PAIR, enum cachetable_dirty dirty, PAIR_ATTR size);
428
// Effect: Unpin a memory object
429
// Modifies: If the memory object is in the cachetable, then OR the dirty flag,
430
// update the size, and release the read lock on the memory object.
431
// Returns: 0 if success, otherwise returns an error number.
432
// Requires: The ct is locked.
434
int toku_cachetable_unpin_ct_prelocked_no_flush(CACHEFILE, PAIR, enum cachetable_dirty dirty, PAIR_ATTR size);
435
// Effect: The same as tokud_cachetable_unpin, except that the ct must not be locked.
436
// Requires: The ct is NOT locked.
438
int toku_cachetable_unpin_and_remove (CACHEFILE, PAIR, CACHETABLE_REMOVE_KEY, void*); /* Removing something already present is OK. */
439
// Effect: Remove an object from the cachetable. Don't write it back.
440
// Requires: The object must be pinned exactly once.
442
// test-only wrapper that use CACHEKEY and fullhash
443
int toku_test_cachetable_unpin(CACHEFILE, CACHEKEY, uint32_t fullhash, enum cachetable_dirty dirty, PAIR_ATTR size);
445
// test-only wrapper that use CACHEKEY and fullhash
446
int toku_test_cachetable_unpin_ct_prelocked_no_flush(CACHEFILE, CACHEKEY, uint32_t fullhash, enum cachetable_dirty dirty, PAIR_ATTR size);
448
// test-only wrapper that use CACHEKEY
449
int toku_test_cachetable_unpin_and_remove (CACHEFILE, CACHEKEY, CACHETABLE_REMOVE_KEY, void*); /* Removing something already present is OK. */
451
int toku_cachefile_prefetch(CACHEFILE cf, CACHEKEY key, uint32_t fullhash,
452
CACHETABLE_WRITE_CALLBACK write_callback,
453
CACHETABLE_FETCH_CALLBACK fetch_callback,
454
CACHETABLE_PARTIAL_FETCH_REQUIRED_CALLBACK pf_req_callback,
455
CACHETABLE_PARTIAL_FETCH_CALLBACK pf_callback,
456
void *read_extraargs, // parameter for fetch_callback, pf_req_callback, and pf_callback
457
bool *doing_prefetch);
458
// Effect: Prefetch a memory object for a given key into the cachetable
459
// Precondition: The cachetable mutex is NOT held.
460
// Postcondition: The cachetable mutex is NOT held.
461
// Returns: 0 if success
463
// 1) The pair's rwlock is acquired (for write) (there is not a deadlock here because the rwlock is a pthread_cond_wait using the cachetable mutex).
464
// Case A: Single-threaded.
465
// A1) Call cachetable_fetch_pair, which
466
// a) Obtains a readlock on the cachefile's fd (to prevent multipler readers at once)
467
// b) Unlocks the cachetable
468
// c) Does the fetch off disk.
469
// d) Locks the cachetable
470
// e) Unlocks the fd lock.
471
// f) Unlocks the pair rwlock.
472
// Case B: Multithreaded
473
// a) Enqueue a cachetable_reader into the workqueue.
474
// b) Unlock the cache table.
475
// c) The enqueue'd job later locks the cachetable, and calls cachetable_fetch_pair (doing the steps in A1 above).
477
int toku_cachetable_assert_all_unpinned (CACHETABLE);
479
int toku_cachefile_count_pinned (CACHEFILE, int /*printthem*/ );
481
// Close the cachefile.
482
// Effects: All of the cached object associated with the cachefile are evicted from
483
// the cachetable. The flush callback is called for each of these objects. The
484
// close function does not return until all of the objects are evicted. The cachefile
486
// If oplsn_valid is true then use oplsn as the LSN of the close instead of asking the logger. oplsn_valid being true is only allowed during recovery, and requires that you are removing the last reference (otherwise the lsn wouldn't make it in.)
487
void toku_cachefile_close (CACHEFILE*, bool oplsn_valid, LSN oplsn);
489
// Return on success (different from pread and pwrite)
490
//int cachefile_pwrite (CACHEFILE, const void *buf, size_t count, toku_off_t offset);
491
//int cachefile_pread (CACHEFILE, void *buf, size_t count, toku_off_t offset);
493
// Get the file descriptor associated with the cachefile
494
// Return the file descriptor
495
// Grabs a read lock protecting the fd
496
int toku_cachefile_get_fd (CACHEFILE);
498
// Get the iname (within the environment) associated with the cachefile
499
// Return the filename
500
char * toku_cachefile_fname_in_env (CACHEFILE cf);
502
// Make it so when the cachefile closes, the underlying file is unlinked
503
void toku_cachefile_unlink_on_close(CACHEFILE cf);
505
// is this cachefile marked as unlink on close?
506
bool toku_cachefile_is_unlink_on_close(CACHEFILE cf);
508
// Return the logger associated with the cachefile
509
TOKULOGGER toku_cachefile_logger (CACHEFILE);
511
// Return the filenum associated with the cachefile
512
FILENUM toku_cachefile_filenum (CACHEFILE);
514
// Effect: Return a 32-bit hash key. The hash key shall be suitable for using with bitmasking for a table of size power-of-two.
515
uint32_t toku_cachetable_hash (CACHEFILE cachefile, CACHEKEY key);
517
uint32_t toku_cachefile_fullhash_of_header (CACHEFILE cachefile);
521
// Print the contents of the cachetable. This is mainly used from gdb
522
void toku_cachetable_print_state (CACHETABLE ct);
524
// Get the state of the cachetable. This is used to verify the cachetable
525
void toku_cachetable_get_state(CACHETABLE ct, int *num_entries_ptr, int *hash_size_ptr, long *size_current_ptr, long *size_limit_ptr);
527
// Get the state of a cachetable entry by key. This is used to verify the cachetable
528
int toku_cachetable_get_key_state(CACHETABLE ct, CACHEKEY key, CACHEFILE cf,
534
// Verify the whole cachetable that the cachefile is in. Slow.
535
void toku_cachefile_verify (CACHEFILE cf);
537
// Verify the cachetable. Slow.
538
void toku_cachetable_verify (CACHETABLE t);
540
// Not for use in production, but useful for testing.
541
void toku_cachetable_print_hash_histogram (void) __attribute__((__visibility__("default")));
543
void toku_cachetable_maybe_flush_some(CACHETABLE ct);
546
uint64_t toku_cachefile_size(CACHEFILE cf);
550
CT_MISSTIME, // how many usec spent waiting for disk read because of cache miss
551
CT_PREFETCHES, // how many times has a block been prefetched into the cachetable?
552
CT_SIZE_CURRENT, // the sum of the sizes of the nodes represented in the cachetable
553
CT_SIZE_LIMIT, // the limit to the sum of the node sizes
554
CT_SIZE_WRITING, // the sum of the sizes of the nodes being written
555
CT_SIZE_NONLEAF, // number of bytes in cachetable belonging to nonleaf nodes
556
CT_SIZE_LEAF, // number of bytes in cachetable belonging to leaf nodes
557
CT_SIZE_ROLLBACK, // number of bytes in cachetable belonging to rollback nodes
558
CT_SIZE_CACHEPRESSURE, // number of bytes causing cache pressure (sum of buffers and workdone counters)
560
CT_CLEANER_EXECUTIONS, // number of times the cleaner thread's loop has executed
562
CT_CLEANER_ITERATIONS, // number of times the cleaner thread runs the cleaner per period
563
CT_WAIT_PRESSURE_COUNT,
564
CT_WAIT_PRESSURE_TIME,
565
CT_LONG_WAIT_PRESSURE_COUNT,
566
CT_LONG_WAIT_PRESSURE_TIME,
572
TOKU_ENGINE_STATUS_ROW_S status[CT_STATUS_NUM_ROWS];
573
} CACHETABLE_STATUS_S, *CACHETABLE_STATUS;
575
void toku_cachetable_get_status(CACHETABLE ct, CACHETABLE_STATUS s);
577
void toku_cachetable_set_env_dir(CACHETABLE ct, const char *env_dir);
578
char * toku_construct_full_name(int count, ...);
579
char * toku_cachetable_get_fname_in_cwd(CACHETABLE ct, const char * fname_in_env);
581
void cachefile_kibbutz_enq (CACHEFILE cf, void (*f)(void*), void *extra);
582
// Effect: Add a job to the cachetable's collection of work to do. Note that function f must call remove_background_job_from_cf()
584
void remove_background_job_from_cf (CACHEFILE cf);
585
// Effect: When a kibbutz job or cleaner thread finishes in a cachefile,
586
// the cachetable must be notified.
588
// test-only function
589
int toku_cachetable_get_checkpointing_user_data_status(void);
591
// test-only function
592
int toku_cleaner_thread_for_test(CACHETABLE ct);
593
int toku_cleaner_thread(void *cleaner_v);
595
// test function. Exported in the ydb layer and used by tests that want to run DRD
596
// The default of 1M is too high for drd tests, so this is a mechanism to set a smaller number.
597
void toku_pair_list_set_lock_size(uint32_t num_locks);
599
// Used by ft-ops.cc to figure out if it has the write lock on a pair.
600
// Pretty hacky and not accurate enough, should be improved at the frwlock
602
__attribute__((const,nonnull))
603
bool toku_ctpair_is_write_locked(PAIR pair);
605
#endif /* CACHETABLE_H */