Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,7 @@ byte[] addToCompactionLogTable(CompactionLogEntry compactionLogEntry) {
try {
activeRocksDB.get().put(compactionLogTableCFHandle, key, value);
} catch (RocksDBException exception) {
// TODO: Revisit exception handling before merging the PR.
throw new RuntimeException(exception);
throw new RocksDBCheckpointDifferException("Failed to persist compaction log entry", exception);
}
return key;
}
Expand Down Expand Up @@ -968,8 +967,7 @@ synchronized void internalGetSSTDiffList(DifferSnapshotVersion src, DifferSnapsh
// Clear output in case of error. Expect fall back to full diff
sameFiles.clear();
differentFiles.clear();
// TODO: Revisit error handling here. Use custom exception?
throw new RuntimeException(errorMsg);
throw new RocksDBCheckpointDifferException(errorMsg);
}

final Set<CompactionNode> nextLevel = new HashSet<>();
Expand Down Expand Up @@ -1143,8 +1141,7 @@ private synchronized Pair<Set<String>, List<byte[]>> getOlderFileNodes() {

}
} catch (InvalidProtocolBufferException exception) {
// TODO: Handle this properly before merging the PR.
throw new RuntimeException(exception);
throw new RocksDBCheckpointDifferException("Failed to parse compaction log entry", exception);
}
return Pair.of(compactionNodes, keysToRemove);
}
Expand All @@ -1156,8 +1153,7 @@ private synchronized void removeKeyFromCompactionLogTable(
activeRocksDB.get().delete(compactionLogTableCFHandle, key);
}
} catch (RocksDBException exception) {
// TODO Handle exception properly before merging the PR.
throw new RuntimeException(exception);
throw new RocksDBCheckpointDifferException("Failed to delete compaction log entries", exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

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.

}
}

Expand All @@ -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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: 'read' -> 'Failed to read'

}
}

Expand All @@ -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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: 'deserialize' -> 'Failed to deserialize'

}
}

Expand All @@ -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
Expand Up @@ -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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: 'read' -> 'Failed to read'

}
}

Expand All @@ -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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: 'write' -> 'Failed to write'

}
}

Expand All @@ -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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: 'delete' -> 'Failed to delete'

}
}

Expand All @@ -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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'deserialize' -> 'Failed to deserialize'

}

iterator = ManagedRocksIterator.managed(
db.get().newIterator(columnFamilyHandle, readOptions));
Expand Down Expand Up @@ -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) {

Choose a reason for hiding this comment

The 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
Expand Up @@ -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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'add' -> 'Failed to add'

}
}

Expand All @@ -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);

Choose a reason for hiding this comment

The 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) {

Choose a reason for hiding this comment

The 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,

Choose a reason for hiding this comment

The 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,

Choose a reason for hiding this comment

The 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));
}
}