-
Notifications
You must be signed in to change notification settings - Fork 593
Harden RocksDB snapshot error handling. #9770
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
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 |
|---|---|---|
|
|
@@ -55,8 +55,7 @@ public boolean add(E entry) { | |
| db.get().put(columnFamilyHandle, rawKey, rawValue); | ||
| return true; | ||
| } catch (IOException | RocksDBException exception) { | ||
| // TODO: [SNAPSHOT] Fail gracefully. | ||
| throw new RuntimeException(exception); | ||
| throw SnapshotStorageException.fromRocksDB("append list entry", toRocks(exception)); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -75,8 +74,7 @@ public E get(int index) { | |
| byte[] rawValue = db.get().get(columnFamilyHandle, rawKey); | ||
| return codecRegistry.asObject(rawValue, entryType); | ||
| } catch (IOException | RocksDBException exception) { | ||
| // TODO: [SNAPSHOT] Fail gracefully. | ||
| throw new RuntimeException(exception); | ||
| throw SnapshotStorageException.fromRocksDB("read list entry", toRocks(exception)); | ||
|
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. nit: 'read' -> 'Failed to read' |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -99,8 +97,7 @@ public E next() { | |
| try { | ||
| return codecRegistry.asObject(rawKey, entryType); | ||
| } catch (IOException exception) { | ||
| // TODO: [SNAPSHOT] Fail gracefully. | ||
| throw new RuntimeException(exception); | ||
| throw SnapshotStorageException.fromIO("deserialize list entry", exception); | ||
|
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. nit: 'deserialize' -> 'Failed to deserialize' |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -110,4 +107,14 @@ public void close() { | |
| } | ||
| }; | ||
| } | ||
|
|
||
| private RocksDBException toRocks(Exception e) { | ||
| if (e instanceof RocksDBException) { | ||
| return (RocksDBException) e; | ||
| } | ||
| if (e.getCause() instanceof RocksDBException) { | ||
| return (RocksDBException) e.getCause(); | ||
| } | ||
| return new RocksDBException(e); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,8 +60,7 @@ public V get(K key) { | |
| byte[] rawValue = db.get().get(columnFamilyHandle, rawKey); | ||
| return codecRegistry.asObject(rawValue, valueType); | ||
| } catch (IOException | RocksDBException exception) { | ||
| // TODO: [SNAPSHOT] Fail gracefully. | ||
| throw new RuntimeException(exception); | ||
| throw SnapshotStorageException.fromRocksDB("read map entry", toRocks(exception)); | ||
|
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. nit: 'read' -> 'Failed to read' |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -72,8 +71,7 @@ public void put(K key, V value) { | |
| byte[] rawValue = codecRegistry.asRawData(value); | ||
| db.get().put(columnFamilyHandle, rawKey, rawValue); | ||
| } catch (IOException | RocksDBException exception) { | ||
| // TODO: [SNAPSHOT] Fail gracefully. | ||
| throw new RuntimeException(exception); | ||
| throw SnapshotStorageException.fromRocksDB("write map entry", toRocks(exception)); | ||
|
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. nit: 'write' -> 'Failed to write' |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -83,8 +81,7 @@ public void remove(K key) { | |
| byte[] rawKey = codecRegistry.asRawData(key); | ||
| db.get().delete(columnFamilyHandle, rawKey); | ||
| } catch (IOException | RocksDBException exception) { | ||
| // TODO: [SNAPSHOT] Fail gracefully. | ||
| throw new RuntimeException(exception); | ||
| throw SnapshotStorageException.fromRocksDB("delete map entry", toRocks(exception)); | ||
|
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. nit: 'delete' -> 'Failed to delete' |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -111,10 +108,9 @@ public ClosableIterator<Map.Entry<K, V>> iterator(Optional<K> lowerBound, | |
| } else { | ||
| upperBoundSlice = null; | ||
| } | ||
| } catch (IOException exception) { | ||
| // TODO: [SNAPSHOT] Fail gracefully. | ||
| throw new RuntimeException(exception); | ||
| } | ||
| } catch (IOException exception) { | ||
| throw SnapshotStorageException.fromIO("deserialize map entry", exception); | ||
|
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. 'deserialize' -> 'Failed to deserialize' |
||
| } | ||
|
|
||
| iterator = ManagedRocksIterator.managed( | ||
| db.get().newIterator(columnFamilyHandle, readOptions)); | ||
|
|
@@ -165,16 +161,26 @@ public V setValue(V value) { | |
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| iterator.close(); | ||
| readOptions.close(); | ||
| if (upperBoundSlice != null) { | ||
| upperBoundSlice.close(); | ||
| } | ||
| if (lowerBoundSlice != null) { | ||
| lowerBoundSlice.close(); | ||
| } | ||
| public void close() { | ||
| iterator.close(); | ||
| readOptions.close(); | ||
| if (upperBoundSlice != null) { | ||
| upperBoundSlice.close(); | ||
| } | ||
| if (lowerBoundSlice != null) { | ||
| lowerBoundSlice.close(); | ||
| } | ||
| }; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| private RocksDBException toRocks(Exception e) { | ||
|
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. code duplication, should be moved to the Utility class. |
||
| if (e instanceof RocksDBException) { | ||
| return (RocksDBException) e; | ||
| } | ||
| if (e.getCause() instanceof RocksDBException) { | ||
| return (RocksDBException) e.getCause(); | ||
| } | ||
| return new RocksDBException(e); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,8 +52,7 @@ public void add(E entry) { | |
| byte[] rawValue = codecRegistry.asRawData(emptyByteArray); | ||
| db.get().put(columnFamilyHandle, rawKey, rawValue); | ||
| } catch (IOException | RocksDBException exception) { | ||
| // TODO: [SNAPSHOT] Fail gracefully. | ||
| throw new RuntimeException(exception); | ||
| throw SnapshotStorageException.fromRocksDB("add set entry", toRocks(exception)); | ||
|
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. 'add' -> 'Failed to add' |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -76,15 +75,24 @@ public E next() { | |
| try { | ||
| return codecRegistry.asObject(rawKey, entryType); | ||
| } catch (IOException exception) { | ||
| // TODO: [SNAPSHOT] Fail gracefully. | ||
| throw new RuntimeException(exception); | ||
| throw SnapshotStorageException.fromIO("deserialize set entry", exception); | ||
|
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. 'deserialize' -> 'Failed to deserialize' |
||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| managedRocksIterator.close(); | ||
| } | ||
| }; | ||
| public void close() { | ||
| managedRocksIterator.close(); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| private RocksDBException toRocks(Exception e) { | ||
|
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. duplicated code, should be moved to the utility class |
||
| if (e instanceof RocksDBException) { | ||
| return (RocksDBException) e; | ||
| } | ||
| if (e.getCause() instanceof RocksDBException) { | ||
| return (RocksDBException) e.getCause(); | ||
| } | ||
| return new RocksDBException(e); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * 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.ozone.om.snapshot; | ||
|
|
||
| import java.io.UncheckedIOException; | ||
| import org.apache.hadoop.hdds.utils.db.RocksDatabaseException; | ||
| import org.rocksdb.RocksDBException; | ||
|
|
||
| /** | ||
| * Unchecked wrapper for snapshot metadata store failures. | ||
| */ | ||
| public class SnapshotStorageException extends RuntimeException { | ||
|
|
||
| public SnapshotStorageException(String message, Exception cause) { | ||
| super(message, cause); | ||
| } | ||
|
|
||
| public static SnapshotStorageException fromRocksDB(String op, | ||
| RocksDBException e) { | ||
| return new SnapshotStorageException("Failed to " + op, | ||
|
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. adding prefix to the message inside ctor would prevent developers from grepping the message in code. |
||
| new RocksDatabaseException("Failed to " + op, e)); | ||
| } | ||
|
|
||
| public static SnapshotStorageException fromIO(String op, | ||
| java.io.IOException e) { | ||
| return new SnapshotStorageException("Failed to " + op, | ||
|
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. adding prefix to the message inside ctor would prevent developers from grepping the message in code. |
||
| new UncheckedIOException(e)); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: 'append' -> 'Append' to be consistent with other messages.