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 #include <climits>
6 #include <cstdint>
7 #include <utility>
8 
9 #include "include/org_rocksdb_test_TestableEventListener.h"
10 #include "rocksdb/listener.h"
11 #include "rocksdb/status.h"
12 #include "rocksdb/table_properties.h"
13 
14 using namespace ROCKSDB_NAMESPACE;
15 
newTablePropertiesForTest()16 static TableProperties newTablePropertiesForTest() {
17   TableProperties table_properties;
18   table_properties.data_size = UINT64_MAX;
19   table_properties.index_size = UINT64_MAX;
20   table_properties.index_partitions = UINT64_MAX;
21   table_properties.top_level_index_size = UINT64_MAX;
22   table_properties.index_key_is_user_key = UINT64_MAX;
23   table_properties.index_value_is_delta_encoded = UINT64_MAX;
24   table_properties.filter_size = UINT64_MAX;
25   table_properties.raw_key_size = UINT64_MAX;
26   table_properties.raw_value_size = UINT64_MAX;
27   table_properties.num_data_blocks = UINT64_MAX;
28   table_properties.num_entries = UINT64_MAX;
29   table_properties.num_deletions = UINT64_MAX;
30   table_properties.num_merge_operands = UINT64_MAX;
31   table_properties.num_range_deletions = UINT64_MAX;
32   table_properties.format_version = UINT64_MAX;
33   table_properties.fixed_key_len = UINT64_MAX;
34   table_properties.column_family_id = UINT64_MAX;
35   table_properties.creation_time = UINT64_MAX;
36   table_properties.oldest_key_time = UINT64_MAX;
37   table_properties.file_creation_time = UINT64_MAX;
38   table_properties.slow_compression_estimated_data_size = UINT64_MAX;
39   table_properties.fast_compression_estimated_data_size = UINT64_MAX;
40   table_properties.db_id = "dbId";
41   table_properties.db_session_id = "sessionId";
42   table_properties.column_family_name = "columnFamilyName";
43   table_properties.filter_policy_name = "filterPolicyName";
44   table_properties.comparator_name = "comparatorName";
45   table_properties.merge_operator_name = "mergeOperatorName";
46   table_properties.prefix_extractor_name = "prefixExtractorName";
47   table_properties.property_collectors_names = "propertyCollectorsNames";
48   table_properties.compression_name = "compressionName";
49   table_properties.compression_options = "compressionOptions";
50   table_properties.user_collected_properties = {{"key", "value"}};
51   table_properties.readable_properties = {{"key", "value"}};
52   table_properties.properties_offsets = {{"key", UINT64_MAX}};
53   return table_properties;
54 }
55 
56 /*
57  * Class:     org_rocksdb_test_TestableEventListener
58  * Method:    invokeAllCallbacks
59  * Signature: (J)V
60  */
Java_org_rocksdb_test_TestableEventListener_invokeAllCallbacks(JNIEnv *,jclass,jlong jhandle)61 void Java_org_rocksdb_test_TestableEventListener_invokeAllCallbacks(
62     JNIEnv *, jclass, jlong jhandle) {
63   const auto &el =
64       *reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::EventListener> *>(
65           jhandle);
66 
67   TableProperties table_properties = newTablePropertiesForTest();
68 
69   FlushJobInfo flush_job_info;
70   flush_job_info.cf_id = INT_MAX;
71   flush_job_info.cf_name = "testColumnFamily";
72   flush_job_info.file_path = "/file/path";
73   flush_job_info.file_number = UINT64_MAX;
74   flush_job_info.oldest_blob_file_number = UINT64_MAX;
75   flush_job_info.thread_id = UINT64_MAX;
76   flush_job_info.job_id = INT_MAX;
77   flush_job_info.triggered_writes_slowdown = true;
78   flush_job_info.triggered_writes_stop = true;
79   flush_job_info.smallest_seqno = UINT64_MAX;
80   flush_job_info.largest_seqno = UINT64_MAX;
81   flush_job_info.table_properties = table_properties;
82   flush_job_info.flush_reason = FlushReason::kManualFlush;
83 
84   el->OnFlushCompleted(nullptr, flush_job_info);
85   el->OnFlushBegin(nullptr, flush_job_info);
86 
87   Status status = Status::Incomplete(Status::SubCode::kNoSpace);
88 
89   TableFileDeletionInfo file_deletion_info;
90   file_deletion_info.db_name = "dbName";
91   file_deletion_info.file_path = "/file/path";
92   file_deletion_info.job_id = INT_MAX;
93   file_deletion_info.status = status;
94 
95   el->OnTableFileDeleted(file_deletion_info);
96 
97   CompactionJobInfo compaction_job_info;
98   compaction_job_info.cf_id = UINT32_MAX;
99   compaction_job_info.cf_name = "compactionColumnFamily";
100   compaction_job_info.status = status;
101   compaction_job_info.thread_id = UINT64_MAX;
102   compaction_job_info.job_id = INT_MAX;
103   compaction_job_info.base_input_level = INT_MAX;
104   compaction_job_info.output_level = INT_MAX;
105   compaction_job_info.input_files = {"inputFile.sst"};
106   compaction_job_info.input_file_infos = {};
107   compaction_job_info.output_files = {"outputFile.sst"};
108   compaction_job_info.output_file_infos = {};
109   compaction_job_info.table_properties = {
110       {"tableProperties", std::shared_ptr<TableProperties>(
111                               &table_properties, [](TableProperties *) {})}};
112   compaction_job_info.compaction_reason = CompactionReason::kFlush;
113   compaction_job_info.compression = CompressionType::kSnappyCompression;
114 
115   compaction_job_info.stats = CompactionJobStats();
116 
117   el->OnCompactionBegin(nullptr, compaction_job_info);
118   el->OnCompactionCompleted(nullptr, compaction_job_info);
119 
120   TableFileCreationInfo file_creation_info;
121   file_creation_info.file_size = UINT64_MAX;
122   file_creation_info.table_properties = table_properties;
123   file_creation_info.status = status;
124   file_creation_info.file_checksum = "fileChecksum";
125   file_creation_info.file_checksum_func_name = "fileChecksumFuncName";
126   file_creation_info.db_name = "dbName";
127   file_creation_info.cf_name = "columnFamilyName";
128   file_creation_info.file_path = "/file/path";
129   file_creation_info.job_id = INT_MAX;
130   file_creation_info.reason = TableFileCreationReason::kMisc;
131 
132   el->OnTableFileCreated(file_creation_info);
133 
134   TableFileCreationBriefInfo file_creation_brief_info;
135   file_creation_brief_info.db_name = "dbName";
136   file_creation_brief_info.cf_name = "columnFamilyName";
137   file_creation_brief_info.file_path = "/file/path";
138   file_creation_brief_info.job_id = INT_MAX;
139   file_creation_brief_info.reason = TableFileCreationReason::kMisc;
140 
141   el->OnTableFileCreationStarted(file_creation_brief_info);
142 
143   MemTableInfo mem_table_info;
144   mem_table_info.cf_name = "columnFamilyName";
145   mem_table_info.first_seqno = UINT64_MAX;
146   mem_table_info.earliest_seqno = UINT64_MAX;
147   mem_table_info.num_entries = UINT64_MAX;
148   mem_table_info.num_deletes = UINT64_MAX;
149 
150   el->OnMemTableSealed(mem_table_info);
151   el->OnColumnFamilyHandleDeletionStarted(nullptr);
152 
153   ExternalFileIngestionInfo file_ingestion_info;
154   file_ingestion_info.cf_name = "columnFamilyName";
155   file_ingestion_info.external_file_path = "/external/file/path";
156   file_ingestion_info.internal_file_path = "/internal/file/path";
157   file_ingestion_info.global_seqno = UINT64_MAX;
158   file_ingestion_info.table_properties = table_properties;
159   el->OnExternalFileIngested(nullptr, file_ingestion_info);
160 
161   el->OnBackgroundError(BackgroundErrorReason::kFlush, &status);
162 
163   WriteStallInfo write_stall_info;
164   write_stall_info.cf_name = "columnFamilyName";
165   write_stall_info.condition.cur = WriteStallCondition::kDelayed;
166   write_stall_info.condition.prev = WriteStallCondition::kStopped;
167   el->OnStallConditionsChanged(write_stall_info);
168 
169   FileOperationInfo op_info = FileOperationInfo(
170       FileOperationType::kRead, "/file/path",
171       std::make_pair(std::chrono::time_point<std::chrono::system_clock,
172                                              std::chrono::nanoseconds>(
173                          std::chrono::nanoseconds(1600699420000000000ll)),
174                      std::chrono::time_point<std::chrono::steady_clock,
175                                              std::chrono::nanoseconds>(
176                          std::chrono::nanoseconds(1600699420000000000ll))),
177       std::chrono::time_point<std::chrono::steady_clock,
178                               std::chrono::nanoseconds>(
179           std::chrono::nanoseconds(1600699425000000000ll)),
180       status);
181   op_info.offset = UINT64_MAX;
182   op_info.length = SIZE_MAX;
183   op_info.status = status;
184 
185   el->OnFileReadFinish(op_info);
186   el->OnFileWriteFinish(op_info);
187   el->OnFileFlushFinish(op_info);
188   el->OnFileSyncFinish(op_info);
189   el->OnFileRangeSyncFinish(op_info);
190   el->OnFileTruncateFinish(op_info);
191   el->OnFileCloseFinish(op_info);
192   el->ShouldBeNotifiedOnFileIO();
193 
194   bool auto_recovery;
195   el->OnErrorRecoveryBegin(BackgroundErrorReason::kFlush, status,
196                            &auto_recovery);
197   el->OnErrorRecoveryCompleted(status);
198 }
199