Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Supports topic partition increase. (#115)
- Loading branch information
1 parent
b7237f8
commit 20f3366
Showing
13 changed files
with
488 additions
and
120 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- see http://www.mojohaus.org/clirr-maven-plugin/examples/ignored-differences.html --> | ||
<differences> | ||
<difference> | ||
<differenceType>7004</differenceType> | ||
<className>com/google/cloud/pubsublite/spark/*Reader</className> | ||
<method>*</method> | ||
</difference> | ||
<difference> | ||
<differenceType>7005</differenceType> | ||
<className>com/google/cloud/pubsublite/spark/*Reader</className> | ||
<method>*</method> | ||
<to>*</to> | ||
</difference> | ||
</differences> |
47 changes: 47 additions & 0 deletions
47
src/main/java/com/google/cloud/pubsublite/spark/CachedPartitionCountReader.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 2020 Google LLC | ||
* | ||
* 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.google.cloud.pubsublite.spark; | ||
|
||
import com.google.cloud.pubsublite.AdminClient; | ||
import com.google.cloud.pubsublite.PartitionLookupUtils; | ||
import com.google.cloud.pubsublite.TopicPath; | ||
import com.google.common.base.Supplier; | ||
import com.google.common.base.Suppliers; | ||
import java.util.concurrent.TimeUnit; | ||
import javax.annotation.concurrent.ThreadSafe; | ||
|
||
@ThreadSafe | ||
public class CachedPartitionCountReader implements PartitionCountReader { | ||
private final AdminClient adminClient; | ||
private final Supplier<Integer> supplier; | ||
|
||
public CachedPartitionCountReader(AdminClient adminClient, TopicPath topicPath) { | ||
this.adminClient = adminClient; | ||
this.supplier = | ||
Suppliers.memoizeWithExpiration( | ||
() -> PartitionLookupUtils.numPartitions(topicPath, adminClient), 1, TimeUnit.MINUTES); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
adminClient.close(); | ||
} | ||
|
||
public int getPartitionCount() { | ||
return supplier.get(); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
src/main/java/com/google/cloud/pubsublite/spark/PartitionCountReader.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 2020 Google LLC | ||
* | ||
* 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.google.cloud.pubsublite.spark; | ||
|
||
import java.io.Closeable; | ||
|
||
public interface PartitionCountReader extends Closeable { | ||
int getPartitionCount(); | ||
|
||
@Override | ||
void close(); | ||
} |
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.