forked from apache/incubator-hugegraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support parallel compress snapshot (apache#2136)
* add raft default config * delete useless final * fix import style --------- Co-authored-by: imbajin <jin@apache.org>
- Loading branch information
1 parent
901da45
commit 82c7e78
Showing
8 changed files
with
469 additions
and
62 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
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
28 changes: 28 additions & 0 deletions
28
...core/src/main/java/org/apache/hugegraph/backend/store/raft/compress/CompressStrategy.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,28 @@ | ||
/* | ||
* 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.hugegraph.backend.store.raft.compress; | ||
|
||
import java.util.zip.Checksum; | ||
|
||
public interface CompressStrategy { | ||
|
||
void compressZip(String rootDir, String sourceDir, String outputZipFile, | ||
Checksum checksum) throws Throwable; | ||
|
||
void decompressZip(String sourceZipFile, String outputDir, Checksum checksum) throws Throwable; | ||
} |
66 changes: 66 additions & 0 deletions
66
...c/main/java/org/apache/hugegraph/backend/store/raft/compress/CompressStrategyManager.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,66 @@ | ||
/* | ||
* 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.hugegraph.backend.store.raft.compress; | ||
|
||
import org.apache.hugegraph.config.CoreOptions; | ||
import org.apache.hugegraph.config.HugeConfig; | ||
|
||
public class CompressStrategyManager { | ||
|
||
private static byte DEFAULT_STRATEGY = 1; | ||
public static final byte SERIAL_STRATEGY = 1; | ||
public static final byte PARALLEL_STRATEGY = 2; | ||
public static final byte MAX_STRATEGY = 5; | ||
private static CompressStrategy[] compressStrategies = new CompressStrategy[MAX_STRATEGY]; | ||
|
||
static { | ||
addCompressStrategy(SERIAL_STRATEGY, new SerialCompressStrategy()); | ||
} | ||
|
||
private CompressStrategyManager() { | ||
} | ||
|
||
public static void addCompressStrategy(int index, CompressStrategy compressStrategy) { | ||
if (compressStrategies.length <= index) { | ||
CompressStrategy[] newCompressStrategies = new CompressStrategy[index + MAX_STRATEGY]; | ||
System.arraycopy(compressStrategies, 0, newCompressStrategies, 0, | ||
compressStrategies.length); | ||
compressStrategies = newCompressStrategies; | ||
} | ||
compressStrategies[index] = compressStrategy; | ||
} | ||
|
||
public static CompressStrategy getDefault() { | ||
return compressStrategies[DEFAULT_STRATEGY]; | ||
} | ||
|
||
public static void init(final HugeConfig config) { | ||
if (!config.get(CoreOptions.RAFT_SNAPSHOT_PARALLEL_COMPRESS)) { | ||
return; | ||
} | ||
// add parallel compress strategy | ||
if (compressStrategies[PARALLEL_STRATEGY] == null) { | ||
CompressStrategy compressStrategy = new ParallelCompressStrategy( | ||
config.get(CoreOptions.RAFT_SNAPSHOT_COMPRESS_THREADS), | ||
config.get(CoreOptions.RAFT_SNAPSHOT_DECOMPRESS_THREADS)); | ||
CompressStrategyManager.addCompressStrategy( | ||
CompressStrategyManager.PARALLEL_STRATEGY, compressStrategy); | ||
DEFAULT_STRATEGY = PARALLEL_STRATEGY; | ||
} | ||
} | ||
} |
Oops, something went wrong.