|
@@ -68,6 +68,8 @@ import static org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos
|
|
|
.Result.DISK_OUT_OF_SPACE;
|
|
|
import static org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos
|
|
|
.Result.ERROR_IN_COMPACT_DB;
|
|
|
+import static org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos
|
|
|
+ .Result.ERROR_IN_DB_SYNC;
|
|
|
import static org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos
|
|
|
.Result.INVALID_CONTAINER_STATE;
|
|
|
import static org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos
|
|
@@ -298,8 +300,14 @@ public class KeyValueContainer implements Container<KeyValueContainerData> {
|
|
|
|
|
|
@Override
|
|
|
public void quasiClose() throws StorageContainerException {
|
|
|
+ // The DB must be synced during close operation
|
|
|
+ flushAndSyncDB();
|
|
|
+
|
|
|
writeLock();
|
|
|
try {
|
|
|
+ // Second sync should be a very light operation as sync has already
|
|
|
+ // been done outside the lock.
|
|
|
+ flushAndSyncDB();
|
|
|
updateContainerData(containerData::quasiCloseContainer);
|
|
|
} finally {
|
|
|
writeUnlock();
|
|
@@ -308,16 +316,18 @@ public class KeyValueContainer implements Container<KeyValueContainerData> {
|
|
|
|
|
|
@Override
|
|
|
public void close() throws StorageContainerException {
|
|
|
+ // The DB must be synced during close operation
|
|
|
+ flushAndSyncDB();
|
|
|
+
|
|
|
writeLock();
|
|
|
try {
|
|
|
+ // Second sync should be a very light operation as sync has already
|
|
|
+ // been done outside the lock.
|
|
|
+ flushAndSyncDB();
|
|
|
updateContainerData(containerData::closeContainer);
|
|
|
} finally {
|
|
|
writeUnlock();
|
|
|
}
|
|
|
-
|
|
|
- // It is ok if this operation takes a bit of time.
|
|
|
- // Close container is not expected to be instantaneous.
|
|
|
- compactDB();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -365,6 +375,22 @@ public class KeyValueContainer implements Container<KeyValueContainerData> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void flushAndSyncDB() throws StorageContainerException {
|
|
|
+ try {
|
|
|
+ try (ReferenceCountedDB db = BlockUtils.getDB(containerData, config)) {
|
|
|
+ db.getStore().flushDB(true);
|
|
|
+ LOG.info("Container {} is synced with bcsId {}.",
|
|
|
+ containerData.getContainerID(),
|
|
|
+ containerData.getBlockCommitSequenceId());
|
|
|
+ }
|
|
|
+ } catch (StorageContainerException ex) {
|
|
|
+ throw ex;
|
|
|
+ } catch (IOException ex) {
|
|
|
+ LOG.error("Error in DB sync while closing container", ex);
|
|
|
+ throw new StorageContainerException(ex, ERROR_IN_DB_SYNC);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public KeyValueContainerData getContainerData() {
|
|
|
return containerData;
|