-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/multi group snapshot #42
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
306bcf7
(fix) multi-group snapshot with memoryStore
09058f1
(fix) multi-group snapshot with rocksDBStore
3f0ef07
(fix) add multi sst snapshot benchmark
416510c
(fix) add meta check on load snapshot
aace8a5
(fix) add meta check on load snapshot
1ab6d16
(fix) add timer metric with memory snapshot
c6ee322
(fix) typo
3af5ada
(fix) log
6a25eaa
(bugfix) fencing token isolation
c654e12
(bugfix) rename local variable
f80b1e5
(bugfix) fencing token isolation by region
069abf9
(fix) typo
a8a57f9
(fix) region info visibility
5253757
(feat) add comment
cb02a29
(fix) delete existing data on rocksdb restart, because raft will play…
fengjiachun 1f3dc73
(fix) delete existing data on rocksdb restart, because raft will play…
fengjiachun 5f55828
(fix) add restart test #86
fengjiachun d56b96e
(fix) add restart test #86
fengjiachun 45914b7
(fix) update restart test
fengjiachun 977e949
(fix) add error log on splitting fail
fengjiachun 8a0f7cc
(fix) requires
fengjiachun 69a0410
(fix) remove useless code
fengjiachun 13d2d6d
(fix) code refactoring with snapshot
fengjiachun b8590c1
(fix) fix bad name
fengjiachun 30606bb
(fix) typo
fengjiachun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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
130 changes: 130 additions & 0 deletions
130
...kv-core/src/main/java/com/alipay/sofa/jraft/rhea/storage/AbstractKVStoreSnapshotFile.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,130 @@ | ||
/* | ||
* 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 com.alipay.sofa.jraft.rhea.storage; | ||
|
||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.nio.file.Paths; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.zip.ZipOutputStream; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.alipay.sofa.jraft.Closure; | ||
import com.alipay.sofa.jraft.Status; | ||
import com.alipay.sofa.jraft.error.RaftError; | ||
import com.alipay.sofa.jraft.rhea.metadata.Region; | ||
import com.alipay.sofa.jraft.rhea.serialization.Serializer; | ||
import com.alipay.sofa.jraft.rhea.serialization.Serializers; | ||
import com.alipay.sofa.jraft.rhea.util.StackTraceUtil; | ||
import com.alipay.sofa.jraft.rhea.util.ZipUtil; | ||
import com.alipay.sofa.jraft.storage.snapshot.SnapshotReader; | ||
import com.alipay.sofa.jraft.storage.snapshot.SnapshotWriter; | ||
import com.google.protobuf.ByteString; | ||
|
||
import static com.alipay.sofa.jraft.entity.LocalFileMetaOutter.LocalFileMeta; | ||
|
||
/** | ||
* @author jiachun.fjc | ||
*/ | ||
public abstract class AbstractKVStoreSnapshotFile implements KVStoreSnapshotFile { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(AbstractKVStoreSnapshotFile.class); | ||
|
||
private static final String SNAPSHOT_DIR = "kv"; | ||
private static final String SNAPSHOT_ARCHIVE = "kv.zip"; | ||
|
||
protected final Serializer serializer = Serializers.getDefault(); | ||
|
||
@Override | ||
public void save(final SnapshotWriter writer, final Closure done, final Region region, | ||
final ExecutorService executor) { | ||
final String writerPath = writer.getPath(); | ||
final String snapshotPath = Paths.get(writerPath, SNAPSHOT_DIR).toString(); | ||
try { | ||
final LocalFileMeta meta = doSnapshotSave(snapshotPath, region); | ||
executor.execute(() -> compressSnapshot(writer, meta, done)); | ||
} catch (final Throwable t) { | ||
LOG.error("Fail to save snapshot, path={}, file list={}, {}.", writerPath, writer.listFiles(), | ||
StackTraceUtil.stackTrace(t)); | ||
done.run(new Status(RaftError.EIO, "Fail to save snapshot at %s, error is %s", writerPath, | ||
t.getMessage())); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean load(final SnapshotReader reader, final Region region) { | ||
final LocalFileMeta meta = (LocalFileMeta) reader.getFileMeta(SNAPSHOT_ARCHIVE); | ||
final String readerPath = reader.getPath(); | ||
if (meta == null) { | ||
LOG.error("Can't find kv snapshot file, path={}.", readerPath); | ||
return false; | ||
} | ||
final String snapshotPath = Paths.get(readerPath, SNAPSHOT_DIR).toString(); | ||
try { | ||
decompressSnapshot(readerPath); | ||
doSnapshotLoad(snapshotPath, meta, region); | ||
return true; | ||
} catch (final Throwable t) { | ||
LOG.error("Fail to load snapshot, path={}, file list={}, {}.", readerPath, reader.listFiles(), | ||
StackTraceUtil.stackTrace(t)); | ||
return false; | ||
} | ||
} | ||
|
||
abstract LocalFileMeta doSnapshotSave(final String snapshotPath, final Region region) throws Exception; | ||
|
||
abstract void doSnapshotLoad(final String snapshotPath, final LocalFileMeta meta, final Region region) | ||
throws Exception; | ||
|
||
protected void compressSnapshot(final SnapshotWriter writer, final LocalFileMeta meta, final Closure done) { | ||
final String writerPath = writer.getPath(); | ||
final String outputFile = Paths.get(writerPath, SNAPSHOT_ARCHIVE).toString(); | ||
try { | ||
try (final ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outputFile))) { | ||
ZipUtil.compressDirectoryToZipFile(writerPath, SNAPSHOT_DIR, out); | ||
} | ||
if (writer.addFile(SNAPSHOT_ARCHIVE, meta)) { | ||
done.run(Status.OK()); | ||
} else { | ||
done.run(new Status(RaftError.EIO, "Fail to add snapshot file: %s", writerPath)); | ||
} | ||
} catch (final Throwable t) { | ||
LOG.error("Fail to compress snapshot, path={}, file list={}, {}.", writerPath, writer.listFiles(), | ||
StackTraceUtil.stackTrace(t)); | ||
done.run(new Status(RaftError.EIO, "Fail to compress snapshot at %s, error is %s", writerPath, t | ||
.getMessage())); | ||
} | ||
} | ||
|
||
protected void decompressSnapshot(final String readerPath) throws IOException { | ||
final String sourceFile = Paths.get(readerPath, SNAPSHOT_ARCHIVE).toString(); | ||
ZipUtil.unzipFile(sourceFile, readerPath); | ||
} | ||
|
||
protected <T> T readMetadata(final LocalFileMeta meta, final Class<T> cls) { | ||
final ByteString userMeta = meta.getUserMeta(); | ||
return this.serializer.readObject(userMeta.toByteArray(), cls); | ||
} | ||
|
||
protected <T> LocalFileMeta buildMetadata(final T metadata) { | ||
return metadata == null ? null : LocalFileMeta.newBuilder() // | ||
.setUserMeta(ByteString.copyFrom(this.serializer.writeObject(metadata))) // | ||
.build(); | ||
} | ||
} |
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
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
50 changes: 50 additions & 0 deletions
50
...akv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/storage/KVStoreSnapshotFile.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,50 @@ | ||
/* | ||
* 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 com.alipay.sofa.jraft.rhea.storage; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
|
||
import com.alipay.sofa.jraft.Closure; | ||
import com.alipay.sofa.jraft.rhea.metadata.Region; | ||
import com.alipay.sofa.jraft.storage.snapshot.SnapshotReader; | ||
import com.alipay.sofa.jraft.storage.snapshot.SnapshotWriter; | ||
|
||
/** | ||
* | ||
* @author jiachun.fjc | ||
*/ | ||
public interface KVStoreSnapshotFile { | ||
|
||
/** | ||
* Save a snapshot for the specified region. | ||
* | ||
* @param writer snapshot writer | ||
* @param done callback | ||
* @param region the region to save snapshot | ||
* @param executor the executor to compress snapshot | ||
*/ | ||
void save(final SnapshotWriter writer, final Closure done, final Region region, final ExecutorService executor); | ||
|
||
/** | ||
* Load snapshot for the specified region. | ||
* | ||
* @param reader snapshot reader | ||
* @param region the region to load snapshot | ||
* @return true if load succeed | ||
*/ | ||
boolean load(final SnapshotReader reader, final Region region); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我觉的这里可以搞成全局的静态变量,然后在 static block 里初始化这个变量,这里就变成 getter 了,是不是性能更好点? 如果这个方法调用不频繁,倒也没关系。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
恩,其实现在的代码就是和你描述的思路一样的,因为 isWindows0() 是只供内部调用的,并且有一个静态变量,
private static final boolean IS_WINDOWS = isWindows0();
对使用者开放的方法是 isWindows() , 所以说 isWindows0() 只会被调用一次