forked from raystack/dagger
-
Notifications
You must be signed in to change notification settings - Fork 2
Feat: Add tablestore longbow storage #61
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
Open
ekawinataa
wants to merge
25
commits into
main
Choose a base branch
from
feat-add-tablestore-longbow-storage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
1e3212b
feat: longbow tablestore storage
ekawinataa 0b3a483
revert
ekawinataa 00e40f7
delete LongbowTablestoreProcessor.java
ekawinataa 46cc670
delete LongbowTablestoreWriter.java and revert settings.gradle
ekawinataa 594d4ca
Use proper indexing and column family name for Tablestore
ekawinataa 98b475a
Update build.gradle
ekawinataa f460a71
FIX: checkstyle
ekawinataa 91e3386
Merge branch 'feat-add-tablestore-longbow-storage' of github.com:goto…
ekawinataa 879539c
FIX: test
ekawinataa a6c7dd0
FIX: remove import
ekawinataa 8a8c593
FIX: test
ekawinataa 40798f0
chore: add info stacktrace on build.yml
ekawinataa 85dfe1f
chore: swap ordering
ekawinataa 525dbde
fix: print kv for scanresult data
ekawinataa 9b295e7
fix: print kv for scanresult data
ekawinataa a9d4f6b
fix: print kv for scanresult data
ekawinataa a0fde3e
fix: print kv for scanresult data
ekawinataa eb8941a
test: print
ekawinataa e218bab
test: print
ekawinataa fd96b37
test: print
ekawinataa d34e24b
test: revert debug
ekawinataa b20e28a
fix
ekawinataa a492613
fix: use string instead of byte[]
ekawinataa dbc8ae2
fix: revert
ekawinataa 2567182
fix: RENAME TEST CASE
ekawinataa 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
6 changes: 6 additions & 0 deletions
6
...rc/main/java/com/gotocompany/dagger/core/processors/longbow/enums/LongbowStorageType.java
This file contains hidden or 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,6 @@ | ||
package com.gotocompany.dagger.core.processors.longbow.enums; | ||
|
||
public enum LongbowStorageType { | ||
TABLESTORE, | ||
BIGTABLE | ||
} |
30 changes: 30 additions & 0 deletions
30
...r-core/src/main/java/com/gotocompany/dagger/core/processors/longbow/model/ScanResult.java
This file contains hidden or 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,30 @@ | ||
package com.gotocompany.dagger.core.processors.longbow.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@Builder | ||
public class ScanResult { | ||
private byte[] primaryKey; | ||
private Map<String, Map<String, byte[]>> data; | ||
|
||
public ScanResult(byte[] primaryKey) { | ||
this.primaryKey = primaryKey; | ||
this.data = new HashMap<>(); | ||
} | ||
|
||
public void addData(byte[] columnFamily, byte[] qualifier, byte[] value) { | ||
String columnFamilyString = new String(columnFamily); | ||
if (!data.containsKey(columnFamilyString)) { | ||
data.put(columnFamilyString, new HashMap<>()); | ||
} | ||
data.get(columnFamilyString).put(new String(qualifier), value); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...company/dagger/core/processors/longbow/model/adapters/HBaseResultToScanResultAdapter.java
This file contains hidden or 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,21 @@ | ||
package com.gotocompany.dagger.core.processors.longbow.model.adapters; | ||
|
||
import com.gotocompany.dagger.core.processors.longbow.model.ScanResult; | ||
import org.apache.hadoop.hbase.client.Result; | ||
|
||
import java.util.NavigableMap; | ||
|
||
public class HBaseResultToScanResultAdapter implements ScanResultAdapter<Result> { | ||
|
||
@Override | ||
public ScanResult adapt(Result result) { | ||
ScanResult scanResult = new ScanResult(result.getRow()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add unit test case for this |
||
NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> rowMaps = result.getMap(); | ||
rowMaps.forEach( | ||
(columnFamily, columnMap) -> columnMap.forEach((columnName, timestampMap) -> | ||
scanResult.addData(columnFamily, columnName, timestampMap.firstEntry().getValue())) | ||
); | ||
return scanResult; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...java/com/gotocompany/dagger/core/processors/longbow/model/adapters/ScanResultAdapter.java
This file contains hidden or 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,7 @@ | ||
package com.gotocompany.dagger.core.processors.longbow.model.adapters; | ||
|
||
import com.gotocompany.dagger.core.processors.longbow.model.ScanResult; | ||
|
||
public interface ScanResultAdapter<T> { | ||
ScanResult adapt(T result); | ||
} |
25 changes: 25 additions & 0 deletions
25
...mpany/dagger/core/processors/longbow/model/adapters/TablestoreRowToScanResultAdapter.java
This file contains hidden or 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,25 @@ | ||
package com.gotocompany.dagger.core.processors.longbow.model.adapters; | ||
|
||
import com.alicloud.openservices.tablestore.model.Row; | ||
import com.gotocompany.dagger.core.processors.longbow.model.ScanResult; | ||
|
||
public class TablestoreRowToScanResultAdapter implements ScanResultAdapter<Row> { | ||
|
||
private static final int PRIMARY_COLUMN_INDEX = 0; | ||
|
||
private final String columnFamilyName; | ||
|
||
public TablestoreRowToScanResultAdapter(String columnFamilyName) { | ||
this.columnFamilyName = columnFamilyName; | ||
} | ||
|
||
@Override | ||
public ScanResult adapt(Row row) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add unit test for this |
||
ScanResult scanResult = new ScanResult(row.getPrimaryKey().getPrimaryKeyColumn(PRIMARY_COLUMN_INDEX).getNameRawData()); | ||
row.getColumnsMap() | ||
.forEach((columnName, timestampToValueMap) -> | ||
scanResult.addData(columnFamilyName.getBytes(), columnName.getBytes(), timestampToValueMap.firstEntry().getValue().asBinary())); | ||
return scanResult; | ||
} | ||
|
||
} |
This file contains hidden or 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
88 changes: 88 additions & 0 deletions
88
.../gotocompany/dagger/core/processors/longbow/storage/BigTableLongbowOperationStrategy.java
This file contains hidden or 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,88 @@ | ||
package com.gotocompany.dagger.core.processors.longbow.storage; | ||
|
||
import com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient; | ||
import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest; | ||
import com.google.cloud.bigtable.hbase.BigtableConfiguration; | ||
import com.gotocompany.dagger.common.configuration.Configuration; | ||
import com.gotocompany.dagger.core.processors.longbow.model.ScanResult; | ||
import com.gotocompany.dagger.core.processors.longbow.model.adapters.HBaseResultToScanResultAdapter; | ||
import com.gotocompany.dagger.core.processors.longbow.model.adapters.ScanResultAdapter; | ||
import com.gotocompany.dagger.core.utils.Constants; | ||
import org.apache.hadoop.hbase.TableName; | ||
import org.apache.hadoop.hbase.client.AdvancedScanResultConsumer; | ||
import org.apache.hadoop.hbase.client.AsyncTable; | ||
import org.apache.hadoop.hbase.client.BigtableAsyncConnection; | ||
import org.apache.hadoop.hbase.client.Result; | ||
import org.threeten.bp.Duration; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.stream.Collectors; | ||
|
||
import static com.google.cloud.bigtable.admin.v2.models.GCRules.GCRULES; | ||
|
||
public class BigTableLongbowOperationStrategy implements LongbowOperationStrategy { | ||
|
||
private final BigtableTableAdminClient adminClient; | ||
private final BigtableAsyncConnection tableClient; | ||
private final Map<String, AsyncTable<AdvancedScanResultConsumer>> tables; | ||
private final ScanResultAdapter<Result> scanResultAdapter; | ||
|
||
public BigTableLongbowOperationStrategy(Configuration configuration) throws IOException { | ||
String gcpProjectID = configuration.getString(Constants.PROCESSOR_LONGBOW_GCP_PROJECT_ID_KEY, Constants.PROCESSOR_LONGBOW_GCP_PROJECT_ID_DEFAULT); | ||
String gcpInstanceID = configuration.getString(Constants.PROCESSOR_LONGBOW_GCP_INSTANCE_ID_KEY, Constants.PROCESSOR_LONGBOW_GCP_INSTANCE_ID_DEFAULT); | ||
org.apache.hadoop.conf.Configuration bigTableConfiguration = BigtableConfiguration.configure(gcpProjectID, gcpInstanceID); | ||
this.adminClient = BigtableTableAdminClient.create(gcpProjectID, gcpInstanceID); | ||
this.tableClient = new BigtableAsyncConnection(bigTableConfiguration); | ||
this.tables = new HashMap<>(); | ||
this.scanResultAdapter = new HBaseResultToScanResultAdapter(); | ||
} | ||
|
||
@Override | ||
public boolean tableExists(String tableId) { | ||
return adminClient.exists(tableId); | ||
} | ||
|
||
@Override | ||
public void createTable(Duration maxAgeDuration, String columnFamilyName, String tableId) { | ||
adminClient.createTable(CreateTableRequest.of(tableId).addFamily(columnFamilyName, | ||
GCRULES.union() | ||
.rule(GCRULES.maxVersions(1)) | ||
.rule(GCRULES.maxAge(maxAgeDuration)))); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Void> put(PutRequest putRequest) { | ||
return getTable(putRequest.getTableId()).put(putRequest.get()); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<List<ScanResult>> scanAll(ScanRequest scanRequest) { | ||
return getTable(scanRequest.getTableId()) | ||
.scanAll(scanRequest.get()) | ||
.thenApply(results -> results.stream() | ||
.map(this.scanResultAdapter::adapt) | ||
.collect(Collectors.toList())); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
if (tableClient != null) { | ||
tableClient.close(); | ||
} | ||
if (adminClient != null) { | ||
adminClient.close(); | ||
} | ||
} | ||
|
||
private AsyncTable<AdvancedScanResultConsumer> getTable(String tableId) { | ||
if (!tables.containsKey(tableId)) { | ||
tables.put(tableId, tableClient.getTable(TableName.valueOf(tableId))); | ||
} | ||
return tables.get(tableId); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...java/com/gotocompany/dagger/core/processors/longbow/storage/LongbowOperationStrategy.java
This file contains hidden or 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 @@ | ||
package com.gotocompany.dagger.core.processors.longbow.storage; | ||
|
||
import com.gotocompany.dagger.core.processors.longbow.model.ScanResult; | ||
import org.threeten.bp.Duration; | ||
|
||
import java.io.IOException; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
public interface LongbowOperationStrategy { | ||
|
||
boolean tableExists(String tableId) throws ExecutionException, InterruptedException; | ||
void createTable(Duration maxAgeDuration, String columnFamilyName, String tableId) throws ExecutionException, InterruptedException; | ||
CompletableFuture<Void> put(PutRequest putRequest); | ||
CompletableFuture<List<ScanResult>> scanAll(ScanRequest scanRequest); | ||
void close() throws IOException; | ||
|
||
} |
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.
add unit test case for this method.