You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2021/03/04 19:52:55 UTC

[GitHub] [bookkeeper] dlg99 commented on a change in pull request #2635: Handle corrupted checkpoints

dlg99 commented on a change in pull request #2635:
URL: https://github.com/apache/bookkeeper/pull/2635#discussion_r587748194



##########
File path: stream/statelib/src/main/java/org/apache/bookkeeper/statelib/impl/rocksdb/checkpoint/RocksCheckpointer.java
##########
@@ -103,32 +79,44 @@ private static void cleanupLocalCheckpoints(File checkpointsDir, String checkpoi
         }
     }
 
-    private static Pair<String, CheckpointMetadata> getLatestCheckpoint(
-        String dbPrefix, CheckpointStore checkpointStore) throws IOException {
+    private static CheckpointInfo getLatestCheckpoint(
+        String dbPrefix, CheckpointStore checkpointStore) {
+        List<CheckpointInfo> checkpoints = getCheckpoints(dbPrefix, checkpointStore);
+        if (checkpoints.size() <= 0) {
+            // Even if there are not checkpoints available, there should be a
+            // nullCheckpoint in the list
+            throw new RuntimeException("Checkpoint list can't be empty");
+        }
+        return checkpoints.get(0);
+    }
+
+    public static List<CheckpointInfo> getCheckpoints(String dbPrefix, CheckpointStore store) {
         String remoteCheckpointsPath = RocksUtils.getDestCheckpointsPath(dbPrefix);
-        List<String> files = checkpointStore.listFiles(remoteCheckpointsPath);
-        CheckpointMetadata latestCheckpoint = null;
-        String latestCheckpointId = null;
+        ArrayList<CheckpointInfo> result = new ArrayList<>();
+        result.add(CheckpointInfo.nullCheckpoint());
+        List<String> files;
+        try {
+            files = store.listFiles(remoteCheckpointsPath);
+        } catch (IOException e) {
+            log.warn("No remote checkpoints available. Starting with nullCheckpoint: {}", e);

Review comment:
       remove `{}` to log exception properly

##########
File path: stream/statelib/src/test/java/org/apache/bookkeeper/statelib/impl/kv/TestRocksdbKVStoreCheckpoint.java
##########
@@ -0,0 +1,97 @@
+/*
+ *
+ * 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.bookkeeper.statelib.impl.kv;
+
+import static org.junit.Assert.assertEquals;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.bookkeeper.statelib.impl.rocksdb.checkpoint.CheckpointInfo;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.junit.rules.TestName;
+
+
+
+
+/**
+ * Test cases for Rocksdb KV Store with checkpoints.
+ */
+@Slf4j
+public class TestRocksdbKVStoreCheckpoint {

Review comment:
       following up on 
   
   > So if we restore from older checkpoint, we will replay from older TxId. This can also detect that there is missing data if the starting TxId is not available in the Journal. I am not sure how that is handled currently by DistributedLog. Ideally that should also throw an exception during journal replay.
   
   This change needs a test reproing this case to confirm that the change does not introduce a silent data loss.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org