Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -597,18 +597,14 @@ public void dispose() {
IOUtils.closeQuietly(db);

LOG.info(
"Closed ForSt State Backend. Cleaning up ForSt local working directory {}, remote working directory {}.",
optionsContainer.getLocalBasePath(),
optionsContainer.getRemoteBasePath());
"Closed ForSt State Backend. Cleaning up ForSt: {}.",
optionsContainer.getPathContainer());

try {
optionsContainer.clearDirectories();
} catch (Exception ex) {
LOG.warn(
"Could not delete ForSt local working directory {}, remote working directory {}.",
optionsContainer.getLocalBasePath(),
optionsContainer.getRemoteBasePath(),
ex);
"Could not delete ForSt: {}.", optionsContainer.getPathContainer(), ex);
}

IOUtils.closeQuietly(optionsContainer);
Expand All @@ -630,12 +626,12 @@ public boolean isSafeToReuseKVState() {

@VisibleForTesting
Path getLocalBasePath() {
return optionsContainer.getLocalBasePath();
return optionsContainer.getPathContainer().getLocalBasePath();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is optionsContainer.getPathContainer() ever null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. pathContainer is final and it should never be null

}

@VisibleForTesting
Path getRemoteBasePath() {
return optionsContainer.getRemoteBasePath();
return optionsContainer.getPathContainer().getRemoteBasePath();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,7 @@ public ForStKeyedStateBackend<K> build() throws BackendBuildingException {
// deletion in file mapping manager.
optionsContainer.forceClearRemoteDirectories();
} catch (Exception ex) {
logger.warn(
"Failed to delete ForSt local base path {}, remote base path {}.",
optionsContainer.getLocalBasePath(),
optionsContainer.getRemoteBasePath(),
ex);
logger.warn("Failed to delete ForSt: {}.", optionsContainer.getPathContainer(), ex);
}
IOUtils.closeQuietly(optionsContainer);
IOUtils.closeQuietly(snapshotStrategy);
Expand All @@ -322,9 +318,8 @@ public ForStKeyedStateBackend<K> build() throws BackendBuildingException {
InternalKeyContext<K> keyContext =
new InternalKeyContextImpl<>(keyGroupRange, numberOfKeyGroups);
logger.info(
"Finished building ForSt keyed state-backend at local base path: {}, remote base path: {}.",
optionsContainer.getLocalBasePath(),
optionsContainer.getRemoteBasePath());
"Finished building ForSt keyed state-backend at {}",
optionsContainer.getPathContainer());
return new ForStKeyedStateBackend<>(
backendUID,
executionConfig,
Expand Down Expand Up @@ -360,8 +355,8 @@ private ForStRestoreOperation getForStRestoreOperation(
// working dir. We will implement this in ForStDB later, but before that, we achieved this
// by setting the dbPath to "/" when the dfs directory existed.
Path instanceForStPath =
optionsContainer.getRemoteForStPath() == null
? optionsContainer.getLocalForStPath()
optionsContainer.getPathContainer().getRemoteForStPath() == null
? optionsContainer.getPathContainer().getLocalForStPath()
: new Path("/db");

if (CollectionUtil.isEmptyOrAllElementsNull(restoreStateHandles)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/*
* 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.state.forst;

import org.apache.flink.core.fs.Path;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;

import java.util.Objects;

/** Container for ForSt paths. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be worth describing each path here. The text talks of Forst paths , but there are only 2 of the 6 that mention Forst - localForStPath and remoteForStPath

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments have been added to the code.

public class ForStPathContainer {

private static final Logger LOG = LoggerFactory.getLogger(ForStResourceContainer.class);
public static final String DB_DIR_STRING = "db";

/**
* Local job path. This indicates the parent directory of ForSt, which ends with the Flink
* JobID.
*/
@Nullable private final Path localJobPath;

/**
* Local base path. This includes the information of the subtask that holds ForSt, such as the
* Operator Identifier and subtask index.
*/
@Nullable private final Path localBasePath;

/** Local ForSt path. This is the directory of ForSt DB, which ends with 'db'. */
@Nullable private final Path localForStPath;

/**
* Remote paths of ForSt. Similar to the respective Path mentioned above, but located under the
* remote parent path.
*/
@Nullable private final Path remoteJobPath;

@Nullable private final Path remoteBasePath;
@Nullable private final Path remoteForStPath;

public static ForStPathContainer empty() {
return of(null, null, null, null);
}

public static ForStPathContainer ofLocal(
@Nullable Path localJobPath, @Nullable Path localBasePath) {
return new ForStPathContainer(localJobPath, localBasePath, null, null);
}

public static ForStPathContainer of(
@Nullable Path localJobPath,
@Nullable Path localBasePath,
@Nullable Path remoteJobPath,
@Nullable Path remoteBasePath) {
return new ForStPathContainer(localJobPath, localBasePath, remoteJobPath, remoteBasePath);
}

public ForStPathContainer(
@Nullable Path localJobPath,
@Nullable Path localBasePath,
@Nullable Path remoteJobPath,
@Nullable Path remoteBasePath) {
this.localJobPath = localJobPath;
this.localBasePath = localBasePath;
this.localForStPath = localBasePath != null ? new Path(localBasePath, DB_DIR_STRING) : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have localJobPath, localBasePath and localForStPath which is derived from localBasePath.

I was expecting localJobpath to be a subfolder of localBasePath, is this true? Is this the bean to validate that?

I see localBasePath can be null, in this case localForStPath is set to null, but localJobPath can have a value. What does this mean? The code indicates that it is possible to run without Forst but have a . Have I understood this correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, localJobpath is a subfolder of localBasePath.

basePath,jobPath are allowed to be null, just to stay consistent with the code before this PR. Currently the local paths can only be null in UT tests.


this.remoteJobPath = remoteJobPath;
this.remoteBasePath = remoteBasePath;
this.remoteForStPath =
remoteBasePath != null ? new Path(remoteBasePath, DB_DIR_STRING) : null;

LOG.info(
"ForStPathContainer: localJobPath: {}, localBasePath: {}, localForStPath:{}, remoteJobPath: {}, remoteBasePath: {}, remoteForStPath: {}",
localJobPath,
localBasePath,
localForStPath,
remoteJobPath,
remoteBasePath,
remoteForStPath);
}

public @Nullable Path getLocalJobPath() {
return localJobPath;
}

public @Nullable Path getLocalBasePath() {
return localBasePath;
}

public @Nullable Path getLocalForStPath() {
return localForStPath;
}

public @Nullable Path getRemoteJobPath() {
return remoteJobPath;
}

public @Nullable Path getRemoteBasePath() {
return remoteBasePath;
}

public @Nullable Path getRemoteForStPath() {
return remoteForStPath;
}

public Path getJobPath() {
if (remoteJobPath != null) {
return remoteJobPath;
} else {
return localJobPath;
}
}

public Path getBasePath() {
if (remoteBasePath != null) {
return remoteBasePath;
} else {
return localBasePath;
}
}

public Path getDbPath() {
if (remoteForStPath != null) {
return remoteForStPath;
} else {
return localForStPath;
}
}

@Override
public String toString() {
return "ForStPathContainer(localJobPath = ["
+ localJobPath
+ "] localBasePath = ["
+ localBasePath
+ "] localForStPath = ["
+ localForStPath
+ "] remoteJobPath = ["
+ remoteJobPath
+ "] remoteBasePath = ["
+ remoteBasePath
+ "] remoteForStPath = ["
+ remoteForStPath
+ "])";
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ForStPathContainer that = (ForStPathContainer) o;
return Objects.equals(localJobPath, that.localJobPath)
&& Objects.equals(localBasePath, that.localBasePath)
&& Objects.equals(localForStPath, that.localForStPath)
&& Objects.equals(remoteJobPath, that.remoteJobPath)
&& Objects.equals(remoteBasePath, that.remoteBasePath)
&& Objects.equals(remoteForStPath, that.remoteForStPath);
}

@Override
public int hashCode() {
return Objects.hash(
localJobPath,
localBasePath,
localForStPath,
remoteJobPath,
remoteBasePath,
remoteForStPath);
}
}
Loading