-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[kv] Support index lookup for primary key table
- Loading branch information
1 parent
9803725
commit b95540f
Showing
56 changed files
with
1,762 additions
and
214 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
fluss-client/src/main/java/com/alibaba/fluss/client/lookup/AbstractLookup.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,41 @@ | ||
/* | ||
* Copyright (c) 2024 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed 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 com.alibaba.fluss.client.lookup; | ||
|
||
import com.alibaba.fluss.annotation.Internal; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** Abstract Class to represent a lookup operation. */ | ||
@Internal | ||
public abstract class AbstractLookup { | ||
|
||
private final byte[] key; | ||
|
||
public AbstractLookup(byte[] key) { | ||
this.key = key; | ||
} | ||
|
||
public byte[] key() { | ||
return key; | ||
} | ||
|
||
public abstract LookupType lookupType(); | ||
|
||
public abstract CompletableFuture<List<byte[]>> future(); | ||
} |
47 changes: 47 additions & 0 deletions
47
fluss-client/src/main/java/com/alibaba/fluss/client/lookup/AbstractLookupBatch.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,47 @@ | ||
/* | ||
* Copyright (c) 2024 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed 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 com.alibaba.fluss.client.lookup; | ||
|
||
import com.alibaba.fluss.annotation.Internal; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** An abstract lookup batch. */ | ||
@Internal | ||
public abstract class AbstractLookupBatch { | ||
|
||
protected final List<AbstractLookup> lookups; | ||
|
||
public AbstractLookupBatch() { | ||
this.lookups = new ArrayList<>(); | ||
} | ||
|
||
public void addLookup(AbstractLookup lookup) { | ||
lookups.add(lookup); | ||
} | ||
|
||
public List<AbstractLookup> lookups() { | ||
return lookups; | ||
} | ||
|
||
/** Complete the lookup operations using given values . */ | ||
public abstract void complete(List<List<byte[]>> values); | ||
|
||
/** Complete the get operations with given exception. */ | ||
public abstract void completeExceptionally(Exception exception); | ||
} |
70 changes: 70 additions & 0 deletions
70
fluss-client/src/main/java/com/alibaba/fluss/client/lookup/IndexLookup.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,70 @@ | ||
/* | ||
* Copyright (c) 2024 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed 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 com.alibaba.fluss.client.lookup; | ||
|
||
import com.alibaba.fluss.annotation.Internal; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* Class to represent an index lookup operation, it contains the table id, bucketNums and related | ||
* CompletableFuture. | ||
*/ | ||
@Internal | ||
public class IndexLookup extends AbstractLookup { | ||
private final int destination; | ||
private final long tableId; | ||
private final int bucketId; | ||
private final String indexName; | ||
private final CompletableFuture<List<byte[]>> future; | ||
|
||
public IndexLookup( | ||
int destination, long tableId, int bucketId, String indexName, byte[] indexKey) { | ||
super(indexKey); | ||
this.destination = destination; | ||
this.tableId = tableId; | ||
this.bucketId = bucketId; | ||
this.indexName = indexName; | ||
this.future = new CompletableFuture<>(); | ||
} | ||
|
||
public int destination() { | ||
return destination; | ||
} | ||
|
||
public long tableId() { | ||
return tableId; | ||
} | ||
|
||
public int bucketId() { | ||
return bucketId; | ||
} | ||
|
||
public String indexName() { | ||
return indexName; | ||
} | ||
|
||
public CompletableFuture<List<byte[]>> future() { | ||
return future; | ||
} | ||
|
||
@Override | ||
public LookupType lookupType() { | ||
return LookupType.INDEX_LOOKUP; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
fluss-client/src/main/java/com/alibaba/fluss/client/lookup/IndexLookupBatch.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,65 @@ | ||
/* | ||
* Copyright (c) 2024 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed 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 com.alibaba.fluss.client.lookup; | ||
|
||
import com.alibaba.fluss.annotation.Internal; | ||
import com.alibaba.fluss.exception.FlussRuntimeException; | ||
import com.alibaba.fluss.metadata.TableBucket; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* A batch that contains the index operations that send to same destination and some table together. | ||
*/ | ||
@Internal | ||
public class IndexLookupBatch extends AbstractLookupBatch { | ||
|
||
private final TableBucket tableBucket; | ||
|
||
public IndexLookupBatch(TableBucket tableBucket) { | ||
super(); | ||
this.tableBucket = tableBucket; | ||
} | ||
|
||
public TableBucket tableBucket() { | ||
return tableBucket; | ||
} | ||
|
||
@Override | ||
public void complete(List<List<byte[]>> values) { | ||
if (values.size() != lookups.size()) { | ||
completeExceptionally( | ||
new FlussRuntimeException( | ||
String.format( | ||
"The number of values return by index lookup request is not equal to the number of " | ||
+ "index lookups send. Got %d values, but expected %d.", | ||
values.size(), lookups.size()))); | ||
} else { | ||
for (int i = 0; i < values.size(); i++) { | ||
AbstractLookup lookup = lookups.get(i); | ||
lookup.future().complete(values.get(i)); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void completeExceptionally(Exception exception) { | ||
for (AbstractLookup get : lookups) { | ||
get.future().completeExceptionally(exception); | ||
} | ||
} | ||
} |
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.