-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce FlintIndexStateModelService
Signed-off-by: Tomoyuki Morita <[email protected]>
- Loading branch information
Showing
23 changed files
with
358 additions
and
118 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
20 changes: 20 additions & 0 deletions
20
...src/main/java/org/opensearch/sql/spark/execution/statestore/OpenSearchStateStoreUtil.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,20 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.spark.execution.statestore; | ||
|
||
import static org.opensearch.sql.spark.data.constants.SparkConstants.SPARK_REQUEST_BUFFER_INDEX_NAME; | ||
|
||
import java.util.Locale; | ||
import lombok.experimental.UtilityClass; | ||
|
||
@UtilityClass | ||
public class OpenSearchStateStoreUtil { | ||
|
||
public static String getIndexName(String datasourceName) { | ||
return String.format( | ||
"%s_%s", SPARK_REQUEST_BUFFER_INDEX_NAME, datasourceName.toLowerCase(Locale.ROOT)); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
spark/src/main/java/org/opensearch/sql/spark/flint/FlintIndexStateModelService.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,26 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.spark.flint; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Abstraction over flint index state storage. | ||
* Flint index state will maintain the status of each flint index. | ||
*/ | ||
public interface FlintIndexStateModelService { | ||
FlintIndexStateModel createFlintIndexStateModel( | ||
FlintIndexStateModel flintIndexStateModel, String datasourceName); | ||
|
||
Optional<FlintIndexStateModel> getFlintIndexStateModel(String id, String datasourceName); | ||
|
||
FlintIndexStateModel updateFlintIndexState( | ||
FlintIndexStateModel flintIndexStateModel, | ||
FlintIndexState flintIndexState, | ||
String datasourceName); | ||
|
||
boolean deleteFlintIndexStateModel(String id, String datasourceName); | ||
} |
50 changes: 50 additions & 0 deletions
50
...k/src/main/java/org/opensearch/sql/spark/flint/OpenSearchFlintIndexStateModelService.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 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.spark.flint; | ||
|
||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.opensearch.sql.spark.execution.statestore.OpenSearchStateStoreUtil; | ||
import org.opensearch.sql.spark.execution.statestore.StateStore; | ||
|
||
@RequiredArgsConstructor | ||
public class OpenSearchFlintIndexStateModelService implements FlintIndexStateModelService { | ||
private final StateStore stateStore; | ||
|
||
@Override | ||
public FlintIndexStateModel updateFlintIndexState( | ||
FlintIndexStateModel flintIndexStateModel, | ||
FlintIndexState flintIndexState, | ||
String datasourceName) { | ||
return stateStore.updateState( | ||
flintIndexStateModel, | ||
flintIndexState, | ||
FlintIndexStateModel::copyWithState, | ||
OpenSearchStateStoreUtil.getIndexName(datasourceName)); | ||
} | ||
|
||
@Override | ||
public Optional<FlintIndexStateModel> getFlintIndexStateModel(String id, String datasourceName) { | ||
return stateStore.get( | ||
id, | ||
FlintIndexStateModel::fromXContent, | ||
OpenSearchStateStoreUtil.getIndexName(datasourceName)); | ||
} | ||
|
||
@Override | ||
public FlintIndexStateModel createFlintIndexStateModel( | ||
FlintIndexStateModel flintIndexStateModel, String datasourceName) { | ||
return stateStore.create( | ||
flintIndexStateModel, | ||
FlintIndexStateModel::copy, | ||
OpenSearchStateStoreUtil.getIndexName(datasourceName)); | ||
} | ||
|
||
@Override | ||
public boolean deleteFlintIndexStateModel(String id, String datasourceName) { | ||
return stateStore.delete(id, OpenSearchStateStoreUtil.getIndexName(datasourceName)); | ||
} | ||
} |
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
Oops, something went wrong.