-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZOOKEEPER-2994: Tool required to recover log and snapshot entries wit…
…h CRC errors (3.4) This is the 3.4 version of #487 phunt I've just realized that the patch must introduce a new dependency: commons-cli. Not sure if you're willing to merge it in this case. Author: Andor Molnar <[email protected]> Reviewers: [email protected] Closes #508 from anmolnar/ZOOKEEPER-2994_34 and squashes the following commits: 357ab2b [Andor Molnar] ZOOKEEPER-2994. Removed dependency of commons.cli. Use custom impl instead. 3bc2e5f [Andor Molnar] ZOOKEEPER-2994: Tool required to recover log and snapshot entries with CRC errors Change-Id: I7def29dc338726c3eccb0a4fd4530a1ffb0f3932
- Loading branch information
Showing
33 changed files
with
967 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@echo off | ||
REM Licensed to the Apache Software Foundation (ASF) under one or more | ||
REM contributor license agreements. See the NOTICE file distributed with | ||
REM this work for additional information regarding copyright ownership. | ||
REM The ASF licenses this file to You under the Apache License, Version 2.0 | ||
REM (the "License"); you may not use this file except in compliance with | ||
REM the License. You may obtain a copy of the License at | ||
REM | ||
REM http://www.apache.org/licenses/LICENSE-2.0 | ||
REM | ||
REM Unless required by applicable law or agreed to in writing, software | ||
REM distributed under the License is distributed on an "AS IS" BASIS, | ||
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
REM See the License for the specific language governing permissions and | ||
REM limitations under the License. | ||
|
||
setlocal | ||
call "%~dp0zkEnv.cmd" | ||
|
||
set ZOOMAIN=org.apache.zookeeper.server.persistence.TxnLogToolkit | ||
call %JAVA% -cp "%CLASSPATH%" %ZOOMAIN% %* | ||
|
||
endlocal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env bash | ||
|
||
# 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. | ||
|
||
# | ||
# If this scripted is run out of /usr/bin or some other system bin directory | ||
# it should be linked to and not copied. Things like java jar files are found | ||
# relative to the canonical path of this script. | ||
# | ||
|
||
# use POSIX interface, symlink is followed automatically | ||
ZOOBIN="${BASH_SOURCE-$0}" | ||
ZOOBIN="$(dirname "${ZOOBIN}")" | ||
ZOOBINDIR="$(cd "${ZOOBIN}"; pwd)" | ||
|
||
if [ -e "$ZOOBIN/../libexec/zkEnv.sh" ]; then | ||
. "$ZOOBINDIR"/../libexec/zkEnv.sh | ||
else | ||
. "$ZOOBINDIR"/zkEnv.sh | ||
fi | ||
|
||
"$JAVA" -cp "$CLASSPATH" $JVMFLAGS \ | ||
org.apache.zookeeper.server.persistence.TxnLogToolkit "$@" | ||
|
||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/java/main/org/apache/zookeeper/server/persistence/FilePadding.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/** | ||
* 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.zookeeper.server.persistence; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.channels.FileChannel; | ||
|
||
public class FilePadding { | ||
private static final Logger LOG; | ||
private static long preAllocSize = 65536 * 1024; | ||
private static final ByteBuffer fill = ByteBuffer.allocateDirect(1); | ||
|
||
static { | ||
LOG = LoggerFactory.getLogger(FileTxnLog.class); | ||
|
||
String size = System.getProperty("zookeeper.preAllocSize"); | ||
if (size != null) { | ||
try { | ||
preAllocSize = Long.parseLong(size) * 1024; | ||
} catch (NumberFormatException e) { | ||
LOG.warn(size + " is not a valid value for preAllocSize"); | ||
} | ||
} | ||
} | ||
|
||
private long currentSize; | ||
|
||
/** | ||
* method to allow setting preallocate size | ||
* of log file to pad the file. | ||
* | ||
* @param size the size to set to in bytes | ||
*/ | ||
public static void setPreallocSize(long size) { | ||
preAllocSize = size; | ||
} | ||
|
||
public void setCurrentSize(long currentSize) { | ||
this.currentSize = currentSize; | ||
} | ||
|
||
/** | ||
* pad the current file to increase its size to the next multiple of preAllocSize greater than the current size and position | ||
* | ||
* @param fileChannel the fileChannel of the file to be padded | ||
* @throws IOException | ||
*/ | ||
long padFile(FileChannel fileChannel) throws IOException { | ||
long newFileSize = calculateFileSizeWithPadding(fileChannel.position(), currentSize, preAllocSize); | ||
if (currentSize != newFileSize) { | ||
fileChannel.write((ByteBuffer) fill.position(0), newFileSize - fill.remaining()); | ||
currentSize = newFileSize; | ||
} | ||
return currentSize; | ||
} | ||
|
||
/** | ||
* Calculates a new file size with padding. We only return a new size if | ||
* the current file position is sufficiently close (less than 4K) to end of | ||
* file and preAllocSize is > 0. | ||
* | ||
* @param position the point in the file we have written to | ||
* @param fileSize application keeps track of the current file size | ||
* @param preAllocSize how many bytes to pad | ||
* @return the new file size. It can be the same as fileSize if no | ||
* padding was done. | ||
* @throws IOException | ||
*/ | ||
// VisibleForTesting | ||
public static long calculateFileSizeWithPadding(long position, long fileSize, long preAllocSize) { | ||
// If preAllocSize is positive and we are within 4KB of the known end of the file calculate a new file size | ||
if (preAllocSize > 0 && position + 4096 >= fileSize) { | ||
// If we have written more than we have previously preallocated we need to make sure the new | ||
// file size is larger than what we already have | ||
if (position > fileSize) { | ||
fileSize = position + preAllocSize; | ||
fileSize -= fileSize % preAllocSize; | ||
} else { | ||
fileSize += preAllocSize; | ||
} | ||
} | ||
|
||
return fileSize; | ||
} | ||
} |
Oops, something went wrong.