Skip to content

Commit 877bd62

Browse files
committed
Backup bfore travel
1 parent dc62894 commit 877bd62

4 files changed

Lines changed: 128 additions & 5 deletions

File tree

db/db_impl/db_impl.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
#ifdef ROCKSDB_JEMALLOC
7979
#include "port/jemalloc_helper.h"
8080
#endif
81+
#include <iostream>
82+
8183
#include "port/port.h"
8284
#include "rocksdb/cache.h"
8385
#include "rocksdb/compaction_filter.h"
@@ -3825,9 +3827,13 @@ bool DBImpl::KeyMayExist(const ReadOptions& read_options,
38253827
value->assign(pinnable_val.data(), pinnable_val.size());
38263828
}
38273829

3830+
std::cout << "DBImpl::KeyMayExist s : " << s.ToString() << std::endl <<std::flush ;
38283831
// If block_cache is enabled and the index block of the table didn't
38293832
// not present in block_cache, the return value will be Status::Incomplete.
38303833
// In this case, key may still exist in the table.
3834+
if(value_found != nullptr && s.IsIncomplete()) {
3835+
*value_found = false;
3836+
}
38313837
return s.ok() || s.IsIncomplete();
38323838
}
38333839

java/rocksjni/rocksjni.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,10 @@ jboolean key_exists_helper(JNIEnv* env, jlong jdb_handle, jlong jcf_handle,
19261926
const bool may_exist =
19271927
db->KeyMayExist(read_opts, cf_handle, key_slice, &value, &value_found);
19281928

1929+
std::cout << "Key may exist : " << may_exist << std::endl;
1930+
std::cout << "Value found : " << value_found << std::endl << std::flush;
1931+
1932+
19291933
if (may_exist) {
19301934
ROCKSDB_NAMESPACE::Status s;
19311935
{

java/src/test/java/org/rocksdb/KeyExistsTest.java

Lines changed: 103 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
import static java.nio.charset.StandardCharsets.UTF_8;
88
import static org.assertj.core.api.Assertions.assertThat;
99

10+
import java.io.IOException;
1011
import java.nio.ByteBuffer;
11-
import java.util.ArrayList;
12-
import java.util.Arrays;
13-
import java.util.List;
12+
import java.nio.charset.StandardCharsets;
13+
import java.nio.file.Files;
14+
import java.nio.file.Path;
15+
import java.nio.file.Paths;
16+
import java.util.*;
17+
1418
import org.junit.*;
1519
import org.junit.rules.ExpectedException;
1620
import org.junit.rules.TemporaryFolder;
@@ -54,8 +58,6 @@ public void keyExistBug() throws RocksDBException{
5458
assertThat(db2.keyExists("key".getBytes(UTF_8))).isTrue();
5559
assertThat(db2.keyExists("key2".getBytes(UTF_8))).isFalse();
5660
assertThat(db2.keyMayExist("key".getBytes(UTF_8), null)).isTrue();
57-
// db2.flushWal(true);
58-
// db2.compactRange();
5961
}
6062
try(RocksDB db2 = RocksDB.open(dbFolder2.getRoot().getAbsolutePath())) {
6163
assertThat(db2.keyMayExist("key".getBytes(UTF_8), null)).isTrue();
@@ -73,6 +75,102 @@ public void keyExistBug() throws RocksDBException{
7375
}
7476
}
7577

78+
@Test
79+
public void keyExistGenerator() throws RocksDBException, IOException {
80+
81+
final byte[] KNOWN_KEY = "random_key_value".getBytes(UTF_8);
82+
final long PSEUDO_RANDOM_SEED = 15875551233124l;
83+
84+
Path rocksDbPath = Paths.get("/tmp/rocks-test");
85+
if (Files.exists(rocksDbPath)) {
86+
Files.walk(rocksDbPath)
87+
.sorted(Comparator.reverseOrder())
88+
.map(Path::toFile)
89+
.forEach(x -> x.delete());
90+
}
91+
92+
try(Options options = new Options().setCreateIfMissing(true);
93+
TtlDB db2 = TtlDB.open(options, "/tmp/rocks-test", 86400, false);
94+
WriteOptions writeOptions = new WriteOptions()
95+
) {
96+
writeOptions.setDisableWAL(true);
97+
db2.put(KNOWN_KEY, "value".getBytes(UTF_8));
98+
99+
ByteBuffer key = ByteBuffer.allocateDirect(16);
100+
ByteBuffer value = ByteBuffer.allocateDirect(16);
101+
Random r = new Random(PSEUDO_RANDOM_SEED);
102+
for(int i = 0 ; i < 1_000_000 ; i++){
103+
key.clear();
104+
key.putLong(r.nextLong());
105+
key.putLong(r.nextLong());
106+
key.flip();
107+
108+
value.clear();
109+
value.putLong(r.nextLong());
110+
value.putLong(r.nextLong());
111+
value.flip();
112+
113+
db2.put(writeOptions, key, value);
114+
if (i % 50000 == 0) {
115+
System.out.println(i);
116+
}
117+
}
118+
// System.out.print("Compacting ...");
119+
// db.compactRange();
120+
// System.out.println(" [OK]");
121+
}
122+
try(Options options = new Options().setCreateIfMissing(true);
123+
124+
//RocksDB db2 = RocksDB.open(options, "/tmp/rocks-test")
125+
//RocksDB db2 = RocksDB.openReadOnly(options, "/tmp/rocks-test")
126+
TtlDB db2 = TtlDB.open(options, "/tmp/rocks-test", 86400, true);
127+
128+
) {
129+
130+
// assertThat(db2.get("key".getBytes())).isEqualTo("value".getBytes(UTF_8));
131+
Random r = new Random(PSEUDO_RANDOM_SEED);
132+
ByteBuffer key = ByteBuffer.allocateDirect(16);
133+
// for (int i = 0; i < 100; i++) {
134+
// key.clear();
135+
// key.putLong(r.nextLong());
136+
// key.putLong(r.nextLong());
137+
// key.flip();
138+
//
139+
// r.nextLong();
140+
// r.nextLong();
141+
//
142+
// System.out.println(" key : " + i + " exist : " + db2.keyExists(key));
143+
//
144+
// }
145+
System.out.println("Key exist 1 : ");
146+
System.out.flush();
147+
db2.keyExists(KNOWN_KEY);
148+
db2.get(KNOWN_KEY);
149+
System.out.println("Key exists 2 : ");
150+
System.out.flush();
151+
db2.keyExists(KNOWN_KEY);
152+
}
153+
154+
}
155+
156+
@Test
157+
public void verify() throws RocksDBException {
158+
try(Options options = new Options().setCreateIfMissing(true);
159+
160+
//RocksDB db2 = RocksDB.open(options, "/tmp/rocks-test")
161+
//RocksDB db2 = RocksDB.openReadOnly(options, "/tmp/rocks-test")
162+
TtlDB db2 = TtlDB.open(options, "/tmp/rocks-test", 86400, true);
163+
164+
) {
165+
166+
// assertThat(db2.get("key".getBytes())).isEqualTo("value".getBytes(UTF_8));
167+
168+
assertThat(db2.keyExists("key".getBytes(UTF_8))).isTrue();
169+
}
170+
}
171+
172+
173+
76174
@Test
77175
public void keyExists() throws RocksDBException {
78176
db.put("key".getBytes(UTF_8), "value".getBytes(UTF_8));

utilities/ttl/db_ttl_impl.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "utilities/ttl/db_ttl_impl.h"
77

8+
#include <iostream>
9+
810
#include "db/write_batch_internal.h"
911
#include "file/filename.h"
1012
#include "logging/logging.h"
@@ -541,9 +543,22 @@ bool DBWithTTLImpl::KeyMayExist(const ReadOptions& options,
541543
ColumnFamilyHandle* column_family,
542544
const Slice& key, std::string* value,
543545
bool* value_found) {
546+
std::cout << "DBWithTTLImpl::KeyMayExist" << std::endl <<std::flush ;
547+
544548
bool ret = db_->KeyMayExist(options, column_family, key, value, value_found);
549+
std::cout << " DBWithTTLImpl::KeyMayExist ret value : " << ret << std::endl <<std::flush ;
550+
if(value_found != nullptr) {
551+
std::cout << " DBWithTTLImpl::KeyMayExist value_found : " << *value_found << std::endl <<std::flush ;
552+
}
553+
if(value_found != nullptr && *value_found && value != nullptr) {
554+
std::cout << " DBWithTTLImpl::KeyMayExist value.size : " << value->size() << std::endl <<std::flush ;
555+
}
556+
545557
if (ret && value != nullptr && value_found != nullptr && *value_found) {
558+
// std::cout << " DBWithTTLImpl::KeyMayExist SanityCheckTimestamp : " << SanityCheckTimestamp(*value).ToString() << std::endl <<std::flush ;
559+
// std::cout << " DBWithTTLImpl::KeyMayExist StripTS(value) : " << StripTS(value).ToString() << std::endl <<std::flush ;
546560
if (!SanityCheckTimestamp(*value).ok() || !StripTS(value).ok()) {
561+
547562
return false;
548563
}
549564
}

0 commit comments

Comments
 (0)