forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-4579] [RocksDB backend] Add StateBackendFactory and config sho…
…rtcut for the RocksDB Backend This also now packages the RocksDB state backend into the Flink distribution This closes apache#2482
- Loading branch information
1 parent
b5938b0
commit fc730bb
Showing
10 changed files
with
131 additions
and
18 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
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
74 changes: 74 additions & 0 deletions
74
...db/src/main/java/org/apache/flink/contrib/streaming/state/RocksDBStateBackendFactory.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,74 @@ | ||
/* | ||
* 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.flink.contrib.streaming.state; | ||
|
||
import org.apache.flink.configuration.Configuration; | ||
import org.apache.flink.configuration.IllegalConfigurationException; | ||
import org.apache.flink.core.fs.Path; | ||
import org.apache.flink.runtime.state.AbstractStateBackend; | ||
import org.apache.flink.runtime.state.StateBackendFactory; | ||
import org.apache.flink.runtime.state.filesystem.FsStateBackend; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* A factory that creates an {@link org.apache.flink.contrib.streaming.state.RocksDBStateBackend} | ||
* from a configuration. | ||
*/ | ||
public class RocksDBStateBackendFactory implements StateBackendFactory<FsStateBackend> { | ||
|
||
protected static final Logger LOG = LoggerFactory.getLogger(RocksDBStateBackendFactory.class); | ||
|
||
private static final long serialVersionUID = 4906988360901930371L; | ||
|
||
/** The key under which the config stores the directory where checkpoints should be stored */ | ||
public static final String CHECKPOINT_DIRECTORY_URI_CONF_KEY = "state.backend.fs.checkpointdir"; | ||
/** The key under which the config stores the directory where RocksDB should be stored */ | ||
public static final String ROCKSDB_CHECKPOINT_DIRECTORY_URI_CONF_KEY = "state.backend.rocksdb.checkpointdir"; | ||
|
||
@Override | ||
public AbstractStateBackend createFromConfig(Configuration config) throws Exception { | ||
String checkpointDirURI = config.getString(CHECKPOINT_DIRECTORY_URI_CONF_KEY, null); | ||
String rocksdbLocalPath = config.getString(ROCKSDB_CHECKPOINT_DIRECTORY_URI_CONF_KEY, null); | ||
|
||
if (checkpointDirURI == null) { | ||
throw new IllegalConfigurationException( | ||
"Cannot create the RocksDB state backend: The configuration does not specify the " + | ||
"checkpoint directory '" + CHECKPOINT_DIRECTORY_URI_CONF_KEY + '\''); | ||
} | ||
|
||
try { | ||
Path path = new Path(checkpointDirURI); | ||
RocksDBStateBackend backend = new RocksDBStateBackend(path.toUri()); | ||
if (rocksdbLocalPath != null) { | ||
String[] directories = rocksdbLocalPath.split(",|" + File.pathSeparator); | ||
backend.setDbStoragePaths(directories); | ||
} | ||
LOG.info("State backend is set to RocksDB (configured DB storage paths {}, checkpoints to filesystem {} ) ", | ||
backend.getDbStoragePaths(), path); | ||
|
||
return backend; | ||
} | ||
catch (IllegalArgumentException e) { | ||
throw new Exception("Cannot initialize RocksDB State Backend with URI '" | ||
+ checkpointDirURI + '.', e); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...rc/test/java/org/apache/flink/contrib/streaming/state/RocksDBStateBackendFactoryTest.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,36 @@ | ||
/* | ||
* 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.flink.contrib.streaming.state; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class RocksDBStateBackendFactoryTest { | ||
|
||
@Test | ||
public void testFactoryName() { | ||
// construct the name such that it will not be automatically adjusted on refactorings | ||
String factoryName = "org.apache.flink.contrib.streaming.state.Roc"; | ||
factoryName += "ksDBStateBackendFactory"; | ||
|
||
// !!! if this fails, the code in StreamTask.createStateBackend() must be adjusted | ||
assertEquals(factoryName, RocksDBStateBackendFactory.class.getName()); | ||
} | ||
} |
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