1 // Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2 //  This source code is licensed under both the GPLv2 (found in the
3 //  COPYING file in the root directory) and Apache 2.0 License
4 //  (found in the LICENSE.Apache file in the root directory).
5 
6 package org.rocksdb;
7 
8 /**
9  * The logical mapping of tickers defined in rocksdb::Tickers.
10  *
11  * Java byte value mappings don't align 1:1 to the c++ values. c++ rocksdb::Tickers enumeration type
12  * is uint32_t and java org.rocksdb.TickerType is byte, this causes mapping issues when
13  * rocksdb::Tickers value is greater then 127 (0x7F) for jbyte jni interface as range greater is not
14  * available. Without breaking interface in minor versions, value mappings for
15  * org.rocksdb.TickerType leverage full byte range [-128 (-0x80), (0x7F)]. Newer tickers added
16  * should descend into negative values until TICKER_ENUM_MAX reaches -128 (-0x80).
17  */
18 public enum TickerType {
19 
20     /**
21      * total block cache misses
22      *
23      * REQUIRES: BLOCK_CACHE_MISS == BLOCK_CACHE_INDEX_MISS +
24      *     BLOCK_CACHE_FILTER_MISS +
25      *     BLOCK_CACHE_DATA_MISS;
26      */
27     BLOCK_CACHE_MISS((byte) 0x0),
28 
29     /**
30      * total block cache hit
31      *
32      * REQUIRES: BLOCK_CACHE_HIT == BLOCK_CACHE_INDEX_HIT +
33      *     BLOCK_CACHE_FILTER_HIT +
34      *     BLOCK_CACHE_DATA_HIT;
35      */
36     BLOCK_CACHE_HIT((byte) 0x1),
37 
38     BLOCK_CACHE_ADD((byte) 0x2),
39 
40     /**
41      * # of failures when adding blocks to block cache.
42      */
43     BLOCK_CACHE_ADD_FAILURES((byte) 0x3),
44 
45     /**
46      * # of times cache miss when accessing index block from block cache.
47      */
48     BLOCK_CACHE_INDEX_MISS((byte) 0x4),
49 
50     /**
51      * # of times cache hit when accessing index block from block cache.
52      */
53     BLOCK_CACHE_INDEX_HIT((byte) 0x5),
54 
55     /**
56      * # of index blocks added to block cache.
57      */
58     BLOCK_CACHE_INDEX_ADD((byte) 0x6),
59 
60     /**
61      * # of bytes of index blocks inserted into cache
62      */
63     BLOCK_CACHE_INDEX_BYTES_INSERT((byte) 0x7),
64 
65     /**
66      * # of bytes of index block erased from cache
67      */
68     BLOCK_CACHE_INDEX_BYTES_EVICT((byte) 0x8),
69 
70     /**
71      * # of times cache miss when accessing filter block from block cache.
72      */
73     BLOCK_CACHE_FILTER_MISS((byte) 0x9),
74 
75     /**
76      * # of times cache hit when accessing filter block from block cache.
77      */
78     BLOCK_CACHE_FILTER_HIT((byte) 0xA),
79 
80     /**
81      * # of filter blocks added to block cache.
82      */
83     BLOCK_CACHE_FILTER_ADD((byte) 0xB),
84 
85     /**
86      * # of bytes of bloom filter blocks inserted into cache
87      */
88     BLOCK_CACHE_FILTER_BYTES_INSERT((byte) 0xC),
89 
90     /**
91      * # of bytes of bloom filter block erased from cache
92      */
93     BLOCK_CACHE_FILTER_BYTES_EVICT((byte) 0xD),
94 
95     /**
96      * # of times cache miss when accessing data block from block cache.
97      */
98     BLOCK_CACHE_DATA_MISS((byte) 0xE),
99 
100     /**
101      * # of times cache hit when accessing data block from block cache.
102      */
103     BLOCK_CACHE_DATA_HIT((byte) 0xF),
104 
105     /**
106      * # of data blocks added to block cache.
107      */
108     BLOCK_CACHE_DATA_ADD((byte) 0x10),
109 
110     /**
111      * # of bytes of data blocks inserted into cache
112      */
113     BLOCK_CACHE_DATA_BYTES_INSERT((byte) 0x11),
114 
115     /**
116      * # of bytes read from cache.
117      */
118     BLOCK_CACHE_BYTES_READ((byte) 0x12),
119 
120     /**
121      * # of bytes written into cache.
122      */
123     BLOCK_CACHE_BYTES_WRITE((byte) 0x13),
124 
125     /**
126      * # of times bloom filter has avoided file reads.
127      */
128     BLOOM_FILTER_USEFUL((byte) 0x14),
129 
130     /**
131      * # persistent cache hit
132      */
133     PERSISTENT_CACHE_HIT((byte) 0x15),
134 
135     /**
136      * # persistent cache miss
137      */
138     PERSISTENT_CACHE_MISS((byte) 0x16),
139 
140     /**
141      * # total simulation block cache hits
142      */
143     SIM_BLOCK_CACHE_HIT((byte) 0x17),
144 
145     /**
146      * # total simulation block cache misses
147      */
148     SIM_BLOCK_CACHE_MISS((byte) 0x18),
149 
150     /**
151      * # of memtable hits.
152      */
153     MEMTABLE_HIT((byte) 0x19),
154 
155     /**
156      * # of memtable misses.
157      */
158     MEMTABLE_MISS((byte) 0x1A),
159 
160     /**
161      * # of Get() queries served by L0
162      */
163     GET_HIT_L0((byte) 0x1B),
164 
165     /**
166      * # of Get() queries served by L1
HistogramType(final byte value)167      */
168     GET_HIT_L1((byte) 0x1C),
169 
170     /**
171      * # of Get() queries served by L2 and up
172      */
173     GET_HIT_L2_AND_UP((byte) 0x1D),
174 
175     /**
176      * COMPACTION_KEY_DROP_* count the reasons for key drop during compaction
177      * There are 4 reasons currently.
178      */
179 
180     /**
181      * key was written with a newer value.
182      */
183     COMPACTION_KEY_DROP_NEWER_ENTRY((byte) 0x1E),
184 
185     /**
186      * Also includes keys dropped for range del.
187      * The key is obsolete.
188      */
189     COMPACTION_KEY_DROP_OBSOLETE((byte) 0x1F),
190 
191     /**
192      * key was covered by a range tombstone.
193      */
194     COMPACTION_KEY_DROP_RANGE_DEL((byte) 0x20),
195 
196     /**
197      * User compaction function has dropped the key.
198      */
199     COMPACTION_KEY_DROP_USER((byte) 0x21),
200 
201     /**
202      * all keys in range were deleted.
203      */
204     COMPACTION_RANGE_DEL_DROP_OBSOLETE((byte) 0x22),
205 
206     /**
207      * Number of keys written to the database via the Put and Write call's.
208      */
209     NUMBER_KEYS_WRITTEN((byte) 0x23),
210 
211     /**
212      * Number of Keys read.
213      */
214     NUMBER_KEYS_READ((byte) 0x24),
215 
216     /**
217      * Number keys updated, if inplace update is enabled
218      */
219     NUMBER_KEYS_UPDATED((byte) 0x25),
220 
221     /**
222      * The number of uncompressed bytes issued by DB::Put(), DB::Delete(),\
223      * DB::Merge(), and DB::Write().
224      */
225     BYTES_WRITTEN((byte) 0x26),
226 
227     /**
228      * The number of uncompressed bytes read from DB::Get().  It could be
229      * either from memtables, cache, or table files.
230      *
231      * For the number of logical bytes read from DB::MultiGet(),
232      * please use {@link #NUMBER_MULTIGET_BYTES_READ}.
233      */
234     BYTES_READ((byte) 0x27),
235 
236     /**
237      * The number of calls to seek.
238      */
239     NUMBER_DB_SEEK((byte) 0x28),
240 
241     /**
242      * The number of calls to next.
243      */
244     NUMBER_DB_NEXT((byte) 0x29),
245 
246     /**
247      * The number of calls to prev.
248      */
249     NUMBER_DB_PREV((byte) 0x2A),
250 
251     /**
252      * The number of calls to seek that returned data.
253      */
254     NUMBER_DB_SEEK_FOUND((byte) 0x2B),
255 
256     /**
257      * The number of calls to next that returned data.
258      */
259     NUMBER_DB_NEXT_FOUND((byte) 0x2C),
260 
261     /**
262      * The number of calls to prev that returned data.
263      */
264     NUMBER_DB_PREV_FOUND((byte) 0x2D),
265 
266     /**
267      * The number of uncompressed bytes read from an iterator.
268      * Includes size of key and value.
269      */
270     ITER_BYTES_READ((byte) 0x2E),
271 
272     NO_FILE_CLOSES((byte) 0x2F),
273 
274     NO_FILE_OPENS((byte) 0x30),
275 
276     NO_FILE_ERRORS((byte) 0x31),
277 
278     /**
279      * Time system had to wait to do LO-L1 compactions.
280      *
281      * @deprecated
282      */
283     @Deprecated
284     STALL_L0_SLOWDOWN_MICROS((byte) 0x32),
285 
286     /**
287      * Time system had to wait to move memtable to L1.
288      *
289      * @deprecated
290      */
291     @Deprecated
292     STALL_MEMTABLE_COMPACTION_MICROS((byte) 0x33),
293 
294     /**
295      * write throttle because of too many files in L0.
296      *
297      * @deprecated
298      */
299     @Deprecated
300     STALL_L0_NUM_FILES_MICROS((byte) 0x34),
301 
302     /**
303      * Writer has to wait for compaction or flush to finish.
304      */
305     STALL_MICROS((byte) 0x35),
306 
307     /**
308      * The wait time for db mutex.
309      *
310      * Disabled by default. To enable it set stats level to {@link StatsLevel#ALL}
311      */
312     DB_MUTEX_WAIT_MICROS((byte) 0x36),
313 
314     RATE_LIMIT_DELAY_MILLIS((byte) 0x37),
315 
316     /**
317      * Number of iterators created.
318      *
319      */
320     NO_ITERATORS((byte) 0x38),
321 
322     /**
323      * Number of MultiGet calls.
324      */
325     NUMBER_MULTIGET_CALLS((byte) 0x39),
326 
327     /**
328      * Number of MultiGet keys read.
329      */
330     NUMBER_MULTIGET_KEYS_READ((byte) 0x3A),
331 
332     /**
333      * Number of MultiGet bytes read.
334      */
335     NUMBER_MULTIGET_BYTES_READ((byte) 0x3B),
336 
337     /**
338      * Number of deletes records that were not required to be
339      * written to storage because key does not exist.
340      */
341     NUMBER_FILTERED_DELETES((byte) 0x3C),
342     NUMBER_MERGE_FAILURES((byte) 0x3D),
343 
344     /**
345      * Number of times bloom was checked before creating iterator on a
346      * file, and the number of times the check was useful in avoiding
347      * iterator creation (and thus likely IOPs).
348      */
349     BLOOM_FILTER_PREFIX_CHECKED((byte) 0x3E),
350     BLOOM_FILTER_PREFIX_USEFUL((byte) 0x3F),
351 
352     /**
353      * Number of times we had to reseek inside an iteration to skip
354      * over large number of keys with same userkey.
355      */
356     NUMBER_OF_RESEEKS_IN_ITERATION((byte) 0x40),
357 
358     /**
359      * Record the number of calls to {@link RocksDB#getUpdatesSince(long)}. Useful to keep track of
360      * transaction log iterator refreshes.
361      */
362     GET_UPDATES_SINCE_CALLS((byte) 0x41),
363 
364     /**
365      * Miss in the compressed block cache.
366      */
367     BLOCK_CACHE_COMPRESSED_MISS((byte) 0x42),
368 
369     /**
370      * Hit in the compressed block cache.
371      */
372     BLOCK_CACHE_COMPRESSED_HIT((byte) 0x43),
373 
374     /**
375      * Number of blocks added to compressed block cache.
376      */
377     BLOCK_CACHE_COMPRESSED_ADD((byte) 0x44),
378 
379     /**
380      * Number of failures when adding blocks to compressed block cache.
381      */
382     BLOCK_CACHE_COMPRESSED_ADD_FAILURES((byte) 0x45),
383 
384     /**
385      * Number of times WAL sync is done.
386      */
387     WAL_FILE_SYNCED((byte) 0x46),
388 
389     /**
390      * Number of bytes written to WAL.
391      */
392     WAL_FILE_BYTES((byte) 0x47),
393 
394     /**
395      * Writes can be processed by requesting thread or by the thread at the
396      * head of the writers queue.
397      */
398     WRITE_DONE_BY_SELF((byte) 0x48),
399 
400     /**
401      * Equivalent to writes done for others.
402      */
403     WRITE_DONE_BY_OTHER((byte) 0x49),
404 
405     /**
406      * Number of writes ending up with timed-out.
407      */
408     WRITE_TIMEDOUT((byte) 0x4A),
409 
410     /**
411      * Number of Write calls that request WAL.
412      */
413     WRITE_WITH_WAL((byte) 0x4B),
414 
415     /**
416      * Bytes read during compaction.
417      */
418     COMPACT_READ_BYTES((byte) 0x4C),
419 
420     /**
421      * Bytes written during compaction.
422      */
423     COMPACT_WRITE_BYTES((byte) 0x4D),
424 
425     /**
426      * Bytes written during flush.
427      */
428     FLUSH_WRITE_BYTES((byte) 0x4E),
429 
430     /**
431      * Number of table's properties loaded directly from file, without creating
432      * table reader object.
433      */
434     NUMBER_DIRECT_LOAD_TABLE_PROPERTIES((byte) 0x4F),
435     NUMBER_SUPERVERSION_ACQUIRES((byte) 0x50),
436     NUMBER_SUPERVERSION_RELEASES((byte) 0x51),
437     NUMBER_SUPERVERSION_CLEANUPS((byte) 0x52),
438 
439     /**
440      * # of compressions/decompressions executed
441      */
442     NUMBER_BLOCK_COMPRESSED((byte) 0x53),
443     NUMBER_BLOCK_DECOMPRESSED((byte) 0x54),
444 
445     NUMBER_BLOCK_NOT_COMPRESSED((byte) 0x55),
446     MERGE_OPERATION_TOTAL_TIME((byte) 0x56),
447     FILTER_OPERATION_TOTAL_TIME((byte) 0x57),
448 
449     /**
450      * Row cache.
451      */
452     ROW_CACHE_HIT((byte) 0x58),
453     ROW_CACHE_MISS((byte) 0x59),
454 
455     /**
456      * Read amplification statistics.
457      *
458      * Read amplification can be calculated using this formula
459      * (READ_AMP_TOTAL_READ_BYTES / READ_AMP_ESTIMATE_USEFUL_BYTES)
460      *
461      * REQUIRES: ReadOptions::read_amp_bytes_per_bit to be enabled
462      */
463 
464     /**
465      * Estimate of total bytes actually used.
466      */
467     READ_AMP_ESTIMATE_USEFUL_BYTES((byte) 0x5A),
468 
469     /**
470      * Total size of loaded data blocks.
471      */
472     READ_AMP_TOTAL_READ_BYTES((byte) 0x5B),
473 
474     /**
475      * Number of refill intervals where rate limiter's bytes are fully consumed.
476      */
477     NUMBER_RATE_LIMITER_DRAINS((byte) 0x5C),
478 
479     /**
480      * Number of internal skipped during iteration
481      */
482     NUMBER_ITER_SKIP((byte) 0x5D),
483 
484     /**
485      * Number of MultiGet keys found (vs number requested)
486      */
487     NUMBER_MULTIGET_KEYS_FOUND((byte) 0x5E),
488 
489     // -0x01 to fixate the new value that incorrectly changed TICKER_ENUM_MAX
490     /**
491      * Number of iterators created.
492      */
493     NO_ITERATOR_CREATED((byte) -0x01),
494 
495     /**
496      * Number of iterators deleted.
497      */
498     NO_ITERATOR_DELETED((byte) 0x60),
499 
500     /**
501      * Deletions obsoleted before bottom level due to file gap optimization.
502      */
503     COMPACTION_OPTIMIZED_DEL_DROP_OBSOLETE((byte) 0x61),
504 
505     /**
506      * If a compaction was cancelled in sfm to prevent ENOSPC
507      */
508     COMPACTION_CANCELLED((byte) 0x62),
509 
510     /**
511      * # of times bloom FullFilter has not avoided the reads.
512      */
513     BLOOM_FILTER_FULL_POSITIVE((byte) 0x63),
514 
515     /**
516      * # of times bloom FullFilter has not avoided the reads and data actually
517      * exist.
518      */
519     BLOOM_FILTER_FULL_TRUE_POSITIVE((byte) 0x64),
520 
521     /**
522      * BlobDB specific stats
523      * # of Put/PutTTL/PutUntil to BlobDB.
524      */
525     BLOB_DB_NUM_PUT((byte) 0x65),
526 
527     /**
528      * # of Write to BlobDB.
529      */
530     BLOB_DB_NUM_WRITE((byte) 0x66),
531 
532     /**
533      * # of Get to BlobDB.
534      */
535     BLOB_DB_NUM_GET((byte) 0x67),
536 
537     /**
538      * # of MultiGet to BlobDB.
539      */
540     BLOB_DB_NUM_MULTIGET((byte) 0x68),
541 
542     /**
543      * # of Seek/SeekToFirst/SeekToLast/SeekForPrev to BlobDB iterator.
544      */
545     BLOB_DB_NUM_SEEK((byte) 0x69),
546 
547     /**
548      * # of Next to BlobDB iterator.
549      */
550     BLOB_DB_NUM_NEXT((byte) 0x6A),
551 
552     /**
553      * # of Prev to BlobDB iterator.
554      */
555     BLOB_DB_NUM_PREV((byte) 0x6B),
556 
557     /**
558      * # of keys written to BlobDB.
559      */
560     BLOB_DB_NUM_KEYS_WRITTEN((byte) 0x6C),
561 
562     /**
563      * # of keys read from BlobDB.
564      */
565     BLOB_DB_NUM_KEYS_READ((byte) 0x6D),
566 
567     /**
568      * # of bytes (key + value) written to BlobDB.
569      */
570     BLOB_DB_BYTES_WRITTEN((byte) 0x6E),
571 
572     /**
573      * # of bytes (keys + value) read from BlobDB.
574      */
575     BLOB_DB_BYTES_READ((byte) 0x6F),
576 
577     /**
578      * # of keys written by BlobDB as non-TTL inlined value.
579      */
580     BLOB_DB_WRITE_INLINED((byte) 0x70),
581 
582     /**
583      * # of keys written by BlobDB as TTL inlined value.
584      */
585     BLOB_DB_WRITE_INLINED_TTL((byte) 0x71),
586 
587     /**
588      * # of keys written by BlobDB as non-TTL blob value.
589      */
590     BLOB_DB_WRITE_BLOB((byte) 0x72),
591 
592     /**
593      * # of keys written by BlobDB as TTL blob value.
594      */
595     BLOB_DB_WRITE_BLOB_TTL((byte) 0x73),
596 
597     /**
598      * # of bytes written to blob file.
599      */
600     BLOB_DB_BLOB_FILE_BYTES_WRITTEN((byte) 0x74),
601 
602     /**
603      * # of bytes read from blob file.
604      */
605     BLOB_DB_BLOB_FILE_BYTES_READ((byte) 0x75),
606 
607     /**
608      * # of times a blob files being synced.
609      */
610     BLOB_DB_BLOB_FILE_SYNCED((byte) 0x76),
611 
612     /**
613      * # of blob index evicted from base DB by BlobDB compaction filter because
614      * of expiration.
615      */
616     BLOB_DB_BLOB_INDEX_EXPIRED_COUNT((byte) 0x77),
617 
618     /**
619      * Size of blob index evicted from base DB by BlobDB compaction filter
620      * because of expiration.
621      */
622     BLOB_DB_BLOB_INDEX_EXPIRED_SIZE((byte) 0x78),
623 
624     /**
625      * # of blob index evicted from base DB by BlobDB compaction filter because
626      * of corresponding file deleted.
627      */
628     BLOB_DB_BLOB_INDEX_EVICTED_COUNT((byte) 0x79),
629 
630     /**
631      * Size of blob index evicted from base DB by BlobDB compaction filter
632      * because of corresponding file deleted.
633      */
634     BLOB_DB_BLOB_INDEX_EVICTED_SIZE((byte) 0x7A),
635 
636     /**
637      * # of blob files being garbage collected.
638      */
639     BLOB_DB_GC_NUM_FILES((byte) 0x7B),
640 
641     /**
642      * # of blob files generated by garbage collection.
643      */
644     BLOB_DB_GC_NUM_NEW_FILES((byte) 0x7C),
645 
646     /**
647      * # of BlobDB garbage collection failures.
648      */
649     BLOB_DB_GC_FAILURES((byte) 0x7D),
650 
651     /**
652      * # of keys drop by BlobDB garbage collection because they had been
653      * overwritten.
654      */
655     BLOB_DB_GC_NUM_KEYS_OVERWRITTEN((byte) 0x7E),
656 
657     /**
658      * # of keys drop by BlobDB garbage collection because of expiration.
659      */
660     BLOB_DB_GC_NUM_KEYS_EXPIRED((byte) 0x7F),
661 
662     /**
663      * # of keys relocated to new blob file by garbage collection.
664      */
665     BLOB_DB_GC_NUM_KEYS_RELOCATED((byte) -0x02),
666 
667     /**
668      * # of bytes drop by BlobDB garbage collection because they had been
669      * overwritten.
670      */
671     BLOB_DB_GC_BYTES_OVERWRITTEN((byte) -0x03),
672 
673     /**
674      * # of bytes drop by BlobDB garbage collection because of expiration.
675      */
676     BLOB_DB_GC_BYTES_EXPIRED((byte) -0x04),
677 
678     /**
679      * # of bytes relocated to new blob file by garbage collection.
680      */
681     BLOB_DB_GC_BYTES_RELOCATED((byte) -0x05),
682 
683     /**
684      * # of blob files evicted because of BlobDB is full.
685      */
686     BLOB_DB_FIFO_NUM_FILES_EVICTED((byte) -0x06),
687 
688     /**
689      * # of keys in the blob files evicted because of BlobDB is full.
690      */
691     BLOB_DB_FIFO_NUM_KEYS_EVICTED((byte) -0x07),
692 
693     /**
694      * # of bytes in the blob files evicted because of BlobDB is full.
695      */
696     BLOB_DB_FIFO_BYTES_EVICTED((byte) -0x08),
697 
698     /**
699      * These counters indicate a performance issue in WritePrepared transactions.
700      * We should not seem them ticking them much.
701      * # of times prepare_mutex_ is acquired in the fast path.
702      */
703     TXN_PREPARE_MUTEX_OVERHEAD((byte) -0x09),
704 
705     /**
706      * # of times old_commit_map_mutex_ is acquired in the fast path.
707      */
708     TXN_OLD_COMMIT_MAP_MUTEX_OVERHEAD((byte) -0x0A),
709 
710     /**
711      * # of times we checked a batch for duplicate keys.
712      */
713     TXN_DUPLICATE_KEY_OVERHEAD((byte) -0x0B),
714 
715     /**
716      * # of times snapshot_mutex_ is acquired in the fast path.
717      */
718     TXN_SNAPSHOT_MUTEX_OVERHEAD((byte) -0x0C),
719 
720     /**
721      * # of times ::Get returned TryAgain due to expired snapshot seq
722      */
723     TXN_GET_TRY_AGAIN((byte) -0x0D),
724 
725     TICKER_ENUM_MAX((byte) 0x5F);
726 
727     private final byte value;
728 
729     TickerType(final byte value) {
730         this.value = value;
731     }
732 
733     /**
734      * Returns the byte value of the enumerations value
735      *
736      * @return byte representation
737      */
738     public byte getValue() {
739         return value;
740     }
741 
742     /**
743      * Get Ticker type by byte value.
744      *
745      * @param value byte representation of TickerType.
746      *
747      * @return {@link org.rocksdb.TickerType} instance.
748      * @throws java.lang.IllegalArgumentException if an invalid
749      *     value is provided.
750      */
751     public static TickerType getTickerType(final byte value) {
752         for (final TickerType tickerType : TickerType.values()) {
753             if (tickerType.getValue() == value) {
754                 return tickerType;
755             }
756         }
757         throw new IllegalArgumentException(
758             "Illegal value provided for TickerType.");
759     }
760 }
761