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/03 22:37:27 UTC

[GitHub] [bookkeeper] sursingh opened a new pull request #2635: Handle corrupted checkpoints

sursingh opened a new pull request #2635:
URL: https://github.com/apache/bookkeeper/pull/2635


   ### Motivation
   
   If a checkpoint is corrupted, checkpoint restoration will fail. Currently we will keep
   retrying to restore the same checkpoint. The system will never recover from this.
   The only way out is to manually remove the checkpoint from the zookeeper
   
   ### Changes
   
   When a checkpoint is corrupted, we need to try and restore from previous checkpoint.
   This  is done recursively till we hit a checkpoint that works. If none of the checkpoints
   work, we will fallback to a `nullcheckpoint` which will initialize rocksdb from scratch
   and replay all state from journal.
   
   Instead of just dealing with the latest checkpoint, we now return a list of checkpoints
   ordered by age. We then simply walk this list and stop as soon as a checkpoint is
   successfully restored. We currently only keep a single checkpoint,  but with this change
   we can potentially keep `N` checkpoints to provide more robustness. 
   
   > ---
   > In order to uphold a high standard for quality for code contributions, Apache BookKeeper runs various precommit
   > checks for pull requests. A pull request can only be merged when it passes precommit checks.
   >
   > ---
   > Be sure to do all of the following to help us incorporate your contribution
   > quickly and easily:
   >
   > If this PR is a BookKeeper Proposal (BP):
   >
   > - [ ] Make sure the PR title is formatted like:
   >     `<BP-#>: Description of bookkeeper proposal`
   >     `e.g. BP-1: 64 bits ledger is support`
   > - [ ] Attach the master issue link in the description of this PR.
   > - [ ] Attach the google doc link if the BP is written in Google Doc.
   >
   > Otherwise:
   > 
   > - [ ] Make sure the PR title is formatted like:
   >     `<Issue #>: Description of pull request`
   >     `e.g. Issue 123: Description ...`
   > - [ ] Make sure tests pass via `mvn clean apache-rat:check install spotbugs:check`.
   > - [ ] Replace `<Issue #>` in the title with the actual Issue number.
   > 
   > ---
   


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



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

Posted by GitBox <gi...@apache.org>.
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



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

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #2635:
URL: https://github.com/apache/bookkeeper/pull/2635#discussion_r587204090



##########
File path: stream/statelib/src/main/java/org/apache/bookkeeper/statelib/impl/rocksdb/checkpoint/CheckpointInfo.java
##########
@@ -0,0 +1,151 @@
+/*
+ *
+ * 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.rocksdb.checkpoint;
+
+import com.google.common.io.MoreFiles;
+import com.google.common.io.RecursiveDeleteOption;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.UUID;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.bookkeeper.statelib.api.checkpoint.CheckpointStore;
+import org.apache.bookkeeper.statelib.api.exceptions.StateStoreException;
+import org.apache.bookkeeper.stream.proto.kv.store.CheckpointMetadata;
+
+
+/**
+ * CheckpointInfo encapsulated information and operatation for a checkpoint.
+ */
+@Slf4j
+public
+class CheckpointInfo implements Comparable<CheckpointInfo> {

Review comment:
       nit: format "public"

##########
File path: stream/statelib/src/main/java/org/apache/bookkeeper/statelib/impl/rocksdb/checkpoint/RocksCheckpointer.java
##########
@@ -103,32 +79,38 @@ 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);
+        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) {
+            return result;

Review comment:
       can we log this error ?

##########
File path: stream/statelib/src/main/java/org/apache/bookkeeper/statelib/impl/rocksdb/checkpoint/RocksCheckpointer.java
##########
@@ -103,32 +79,38 @@ 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);
+        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) {
+            return result;
+        }
 
         for (String checkpointId : files) {
             String metadataPath = RocksUtils.getDestCheckpointMetadataPath(
                 dbPrefix,
                 checkpointId);
 
-            try (InputStream is = checkpointStore.openInputStream(metadataPath)) {
-                CheckpointMetadata ckpt = CheckpointMetadata.parseFrom(is);
-                if (null == latestCheckpoint) {
-                    latestCheckpointId = checkpointId;
-                    latestCheckpoint = ckpt;
-                } else if (latestCheckpoint.getCreatedAt() < ckpt.getCreatedAt()) {
-                    latestCheckpointId = checkpointId;
-                    latestCheckpoint = ckpt;
-                }
+            try (InputStream is = store.openInputStream(metadataPath)) {
+                result.add(new CheckpointInfo(checkpointId, is));
             } catch (FileNotFoundException fnfe) {
                 log.error("Metadata is corrupt for the checkpoint {}. Skipping it.", checkpointId);
+            } catch (IOException e) {
+                log.error("IO exception {}. Skipping it.", checkpointId);

Review comment:
       can we log the error?

##########
File path: stream/statelib/src/main/java/org/apache/bookkeeper/statelib/impl/rocksdb/checkpoint/RocksCheckpointer.java
##########
@@ -103,32 +79,38 @@ 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);
+        return checkpoints.get(0);

Review comment:
       can we deal with an empty list ?
   maybe it should not happen, but in case it happen we will have a bad runtime exception without a meaningful error message

##########
File path: stream/statelib/src/main/java/org/apache/bookkeeper/statelib/impl/rocksdb/checkpoint/CheckpointInfo.java
##########
@@ -0,0 +1,151 @@
+/*
+ *
+ * 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.rocksdb.checkpoint;
+
+import com.google.common.io.MoreFiles;
+import com.google.common.io.RecursiveDeleteOption;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.UUID;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.bookkeeper.statelib.api.checkpoint.CheckpointStore;
+import org.apache.bookkeeper.statelib.api.exceptions.StateStoreException;
+import org.apache.bookkeeper.stream.proto.kv.store.CheckpointMetadata;
+
+
+/**
+ * CheckpointInfo encapsulated information and operatation for a checkpoint.
+ */
+@Slf4j
+public
+class CheckpointInfo implements Comparable<CheckpointInfo> {
+
+    String id;

Review comment:
       can we make these fields "final"




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



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

Posted by GitBox <gi...@apache.org>.
sursingh commented on a change in pull request #2635:
URL: https://github.com/apache/bookkeeper/pull/2635#discussion_r587622477



##########
File path: stream/statelib/src/main/java/org/apache/bookkeeper/statelib/impl/rocksdb/checkpoint/RocksCheckpointer.java
##########
@@ -103,32 +79,38 @@ 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);
+        return checkpoints.get(0);

Review comment:
       Ideally this will never happen as there should always be a `nullCheckpoint` added to the list. But we add a explicit check to ensure proper error message




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



[GitHub] [bookkeeper] sursingh commented on pull request #2635: Handle corrupted checkpoints

Posted by GitBox <gi...@apache.org>.
sursingh commented on pull request #2635:
URL: https://github.com/apache/bookkeeper/pull/2635#issuecomment-790744821


   @dlg99 Currently there is no explicit truncation of the Journal. There is default setting that drops records older than 72 hours. So if the old checkpoint is older than 72 hours we will be missing the data.
   
   

The way it is currently setup the TxId is stored in the rocks db. We use this to get the last TxId that is available in the checkpoint. After restoring the checkpoint we trigger a replay from the journal starting from the last TxId that we get after restoring the checkpoint. 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 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



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

Posted by GitBox <gi...@apache.org>.
dlg99 commented on pull request #2635:
URL: https://github.com/apache/bookkeeper/pull/2635#issuecomment-790271169


   @sursingh I'd like to clarify my understanding of specific scenario and inner working of the stream store:
   
   Store, i.e. RocksdbKVAsyncStore, writes op to a journal (distributed).
   periodically it checkpoint/writes local rocks db data to the distributed store (BK)
   At some point after checkpoint the store truncates journal.
   Last checkpoint + journal is enough to restore consistent dataset / full data
   
   Now if last checkpoint is corrupt we'll fallback to the previous checkpoint.
   It will pick up whatever journal available (`getDLSNNotLessThanTxId(checkpointedTxId)`) after the checkpoint
   It will not detect if journal data in the range `[checkpointedTxId, firstAvailableInJournalTxId]` is missing.
   The store gets data restored form an older checkpoint + journal that starts after the last (corrupt) checkpoint was created.
   Now the store has lost some data/has inconsistent data.
   
   Is my understanding correct? 


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



[GitHub] [bookkeeper] eolivelli merged pull request #2635: Handle corrupted checkpoints

Posted by GitBox <gi...@apache.org>.
eolivelli merged pull request #2635:
URL: https://github.com/apache/bookkeeper/pull/2635


   


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



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

Posted by GitBox <gi...@apache.org>.
sursingh commented on a change in pull request #2635:
URL: https://github.com/apache/bookkeeper/pull/2635#discussion_r588799654



##########
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:
       DistributedLog starts the replay after the specified transactions. So it skips over the missing records. To address this I have added an explicit verification for starting transaction at the start of journal replay. Also added a test-case to test the same (see testMissingData() above).




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



[GitHub] [bookkeeper] sursingh commented on pull request #2635: Handle corrupted checkpoints

Posted by GitBox <gi...@apache.org>.
sursingh commented on pull request #2635:
URL: https://github.com/apache/bookkeeper/pull/2635#issuecomment-792974495


   @eolivelli I have taken care of your comments. Please take a look.


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