-
Notifications
You must be signed in to change notification settings - Fork 599
HDDS-14225. [WIP] Upgrade RocksDB from 7.7.3 to 10.10.1 #9813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
f822b30
d7e5170
e42ca37
6c960eb
471e6dc
7260d5b
24dd415
7b49c19
21bc915
7270ac0
84da109
f67327d
8ab8f58
b3715f0
602e0db
9ef409e
d416db1
1044f33
4c971a3
ab967ec
763440d
ed1d278
7f3abff
9b6f43f
e2f4ca9
0f389c7
626b417
7b47f38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,16 +99,16 @@ public boolean isEmpty() throws RocksDatabaseException { | |
| @Override | ||
| public boolean isExist(byte[] key) throws RocksDatabaseException { | ||
| rdbMetrics.incNumDBKeyMayExistChecks(); | ||
| final Supplier<byte[]> holder = db.keyMayExist(family, key); | ||
| if (holder == null) { | ||
| return false; // definitely not exists | ||
| } | ||
| final byte[] value = holder.get(); | ||
| if (value != null) { | ||
| return true; // definitely exists | ||
| final Supplier<byte[]> valueSupplier = db.keyMayExist(family, key); | ||
| if (valueSupplier != null) { | ||
| final byte[] value = valueSupplier.get(); | ||
| if (value != null) { | ||
| return true; // definitely exists | ||
| } | ||
| } | ||
|
|
||
| // inconclusive: the key may or may not exist | ||
| // keyMayExist can be a false-negative in some RocksDB setups (for example, | ||
| // snapshot/checkpoint DBs). Verify via point-get to preserve correctness. | ||
| final boolean exists = get(key) != null; | ||
|
Comment on lines
+110
to
112
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am trying to understand more about this comment or how we can reach this stage. The Are we trying to say here that a key may not exist in the snapshot/checkpoint DB but may exist in the active DB? In that case the
|
||
| if (!exists) { | ||
| rdbMetrics.incNumDBKeyMayExistMisses(); | ||
|
|
@@ -141,15 +141,15 @@ public byte[] getSkipCache(byte[] bytes) throws RocksDatabaseException { | |
| @Override | ||
| public byte[] getIfExist(byte[] key) throws RocksDatabaseException { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this API provide definitive result? |
||
| rdbMetrics.incNumDBKeyGetIfExistChecks(); | ||
| final Supplier<byte[]> value = db.keyMayExist(family, key); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from commit history: Fix snapshot existence checks after RocksDB 9.10.0 keyMayExist behavior change Treat keyMayExist/getIfExist as hints and fall back to point reads before deciding not-found:
RocksDB changelog for reference: Behavior Changes
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smengcl can you put the above keyMayExist() behavior change in the PR description. |
||
| if (value == null) { | ||
| return null; // definitely not exists | ||
| } | ||
| if (value.get() != null) { | ||
| return value.get(); // definitely exists | ||
| final Supplier<byte[]> valueSupplier = db.keyMayExist(family, key); | ||
| if (valueSupplier != null) { | ||
| final byte[] value = valueSupplier.get(); | ||
| if (value != null) { | ||
| return value; // definitely exists | ||
| } | ||
| } | ||
|
|
||
| // inconclusive: the key may or may not exist | ||
| // keyMayExist is treated as a hint only; confirm via point-get. | ||
| rdbMetrics.incNumDBKeyGetIfExistGets(); | ||
| final byte[] val = get(key); | ||
| if (val == null) { | ||
|
|
@@ -160,19 +160,21 @@ public byte[] getIfExist(byte[] key) throws RocksDatabaseException { | |
|
|
||
| Integer getIfExist(ByteBuffer key, ByteBuffer outValue) throws RocksDatabaseException { | ||
| rdbMetrics.incNumDBKeyGetIfExistChecks(); | ||
| // keyMayExist may change key buffer position; never reuse the same | ||
| // ByteBuffer instance for fallback point-get. | ||
| final Supplier<Integer> value = db.keyMayExist( | ||
| family, key, outValue.duplicate()); | ||
| if (value == null) { | ||
| return null; // definitely not exists | ||
| } | ||
| if (value.get() != null) { | ||
| // definitely exists, return value size. | ||
| return value.get(); | ||
| family, key.duplicate(), outValue.duplicate()); | ||
| if (value != null) { | ||
| final Integer length = value.get(); | ||
| if (length != null) { | ||
| // definitely exists, return value size. | ||
| return length; | ||
| } | ||
| } | ||
|
|
||
| // inconclusive: the key may or may not exist | ||
| // keyMayExist is treated as a hint only; confirm via point-get. | ||
| rdbMetrics.incNumDBKeyGetIfExistGets(); | ||
| final Integer val = get(key, outValue); | ||
| final Integer val = get(key.duplicate(), outValue); | ||
| if (val == null) { | ||
| rdbMetrics.incNumDBKeyGetIfExistMisses(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,11 +179,17 @@ public boolean isExist(KEY key) throws RocksDatabaseException, CodecException { | |
| } else if (keyCodec.supportCodecBuffer()) { | ||
| // keyCodec.supportCodecBuffer() is enough since value is not needed. | ||
| try (CodecBuffer inKey = keyCodec.toDirectCodecBuffer(key)) { | ||
| // Use zero capacity buffer since value is not needed. | ||
| // Try the lightweight "existence only" check first. | ||
| try (CodecBuffer outValue = CodecBuffer.getEmptyBuffer()) { | ||
| return getFromTableIfExist(inKey, outValue) != null; | ||
| if (getFromTableIfExist(inKey, outValue) != null) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this Ozone API be definitive? |
||
| return true; | ||
| } | ||
| } | ||
| } | ||
| // keyMayExist/getIfExist can still be false-negative in some RocksDB | ||
| // configurations (observed with snapshot/checkpoint DBs), so confirm with | ||
| // a regular point lookup before returning false. | ||
| return getFromTable(key) != null; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this really necessary? This means an additional lookup. |
||
| } else { | ||
| return rawTable.isExist(encodeKey(key)); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.hadoop.hdds.utils.db; | ||
|
|
||
| import static java.nio.charset.StandardCharsets.UTF_8; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.eq; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.util.function.Supplier; | ||
| import org.apache.hadoop.hdds.utils.db.RocksDatabase.ColumnFamily; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Unit tests for {@link RDBTable}. | ||
| */ | ||
| public class TestRDBTable { | ||
|
|
||
| @Test | ||
| public void testGetIfExistByteBufferFallbackUsesFreshKeyBuffer() | ||
| throws Exception { | ||
| RocksDatabase db = mock(RocksDatabase.class); | ||
| ColumnFamily columnFamily = mock(ColumnFamily.class); | ||
| RDBMetrics metrics = mock(RDBMetrics.class); | ||
| RDBTable table = new RDBTable(db, columnFamily, metrics); | ||
|
|
||
| byte[] keyBytes = "key-1".getBytes(UTF_8); | ||
| ByteBuffer key = ByteBuffer.wrap(keyBytes); | ||
| ByteBuffer outValue = ByteBuffer.allocate(64); | ||
|
|
||
| when(db.keyMayExist(eq(columnFamily), any(ByteBuffer.class), | ||
| any(ByteBuffer.class))).thenAnswer(invocation -> { | ||
| // Simulate JNI calls that advance the key position. | ||
| ByteBuffer keyBuffer = invocation.getArgument(1); | ||
| keyBuffer.position(keyBuffer.limit()); | ||
| return (Supplier<Integer>) () -> null; | ||
| }); | ||
|
|
||
| when(db.get(eq(columnFamily), any(ByteBuffer.class), any(ByteBuffer.class))) | ||
| .thenAnswer(invocation -> { | ||
| ByteBuffer keyBuffer = invocation.getArgument(1); | ||
| return keyBuffer.remaining() == keyBytes.length ? 0 : null; | ||
| }); | ||
|
|
||
| Integer result = table.getIfExist(key, outValue); | ||
| assertEquals(0, result); | ||
| assertEquals(0, key.position(), "caller key buffer position must be unchanged"); | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,16 @@ | |
| public class ManagedBloomFilter extends BloomFilter { | ||
| private final UncheckedAutoCloseable leakTracker = track(this); | ||
|
|
||
| @Override | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks unnecessary to me |
||
| public boolean equals(Object obj) { | ||
| return super.equals(obj); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return super.hashCode(); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| try { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.