-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#11350] Add write option to AsyncBufferedMutatorBuilder
- Loading branch information
Showing
11 changed files
with
145 additions
and
44 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
7 changes: 7 additions & 0 deletions
7
...c/main/java/com/navercorp/pinpoint/common/hbase/async/AsyncBufferedMutatorCustomizer.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,7 @@ | ||
package com.navercorp.pinpoint.common.hbase.async; | ||
|
||
import org.apache.hadoop.hbase.client.AsyncBufferedMutatorBuilder; | ||
|
||
public interface AsyncBufferedMutatorCustomizer { | ||
void customize(AsyncBufferedMutatorBuilder builder); | ||
} |
13 changes: 13 additions & 0 deletions
13
.../src/main/java/com/navercorp/pinpoint/common/hbase/async/AsyncBufferedMutatorFactory.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,13 @@ | ||
package com.navercorp.pinpoint.common.hbase.async; | ||
|
||
import org.apache.hadoop.hbase.TableName; | ||
import org.apache.hadoop.hbase.client.AsyncBufferedMutator; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
|
||
public interface AsyncBufferedMutatorFactory { | ||
|
||
AsyncBufferedMutator getBufferedMutator(TableName tableName, ExecutorService pool); | ||
|
||
AsyncBufferedMutator getBufferedMutator(TableName tableName); | ||
} |
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
53 changes: 53 additions & 0 deletions
53
...java/com/navercorp/pinpoint/common/hbase/async/DefaultAsyncBufferedMutatorCustomizer.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,53 @@ | ||
/* | ||
* Copyright 2023 NAVER Corp. | ||
* | ||
* 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.navercorp.pinpoint.common.hbase.async; | ||
|
||
import org.apache.hadoop.hbase.client.AsyncBufferedMutatorBuilder; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
public class DefaultAsyncBufferedMutatorCustomizer implements AsyncBufferedMutatorCustomizer { | ||
|
||
private long writeBufferSize = 100; | ||
private long writeBufferPeriodicFlush = 100; | ||
|
||
public DefaultAsyncBufferedMutatorCustomizer() { | ||
} | ||
|
||
public void setWriteBufferSize(long writeBufferSize) { | ||
this.writeBufferSize = writeBufferSize; | ||
} | ||
|
||
public void setWriteBufferPeriodicFlush(long writeBufferPeriodicFlush) { | ||
this.writeBufferPeriodicFlush = writeBufferPeriodicFlush; | ||
} | ||
|
||
@Override | ||
public void customize(AsyncBufferedMutatorBuilder builder) { | ||
builder.setWriteBufferSize(writeBufferSize); | ||
builder.setWriteBufferPeriodicFlush(writeBufferPeriodicFlush, TimeUnit.MILLISECONDS); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DefaultAsyncBufferedMutatorCustomizer{" + | ||
"writeBufferSize=" + writeBufferSize + | ||
", writeBufferPeriodicFlush=" + writeBufferPeriodicFlush + | ||
'}'; | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
...main/java/com/navercorp/pinpoint/common/hbase/async/HbaseAsyncBufferedMutatorFactory.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,38 @@ | ||
package com.navercorp.pinpoint.common.hbase.async; | ||
|
||
import org.apache.hadoop.hbase.TableName; | ||
import org.apache.hadoop.hbase.client.AsyncBufferedMutator; | ||
import org.apache.hadoop.hbase.client.AsyncBufferedMutatorBuilder; | ||
import org.apache.hadoop.hbase.client.AsyncConnection; | ||
import org.springframework.cache.annotation.Cacheable; | ||
|
||
import java.util.Objects; | ||
import java.util.concurrent.ExecutorService; | ||
|
||
public class HbaseAsyncBufferedMutatorFactory implements AsyncBufferedMutatorFactory { | ||
|
||
private final AsyncConnection connection; | ||
private final AsyncBufferedMutatorCustomizer customizer; | ||
|
||
public HbaseAsyncBufferedMutatorFactory(AsyncConnection connection, AsyncBufferedMutatorCustomizer customizer) { | ||
this.connection = Objects.requireNonNull(connection, "connection"); | ||
this.customizer = Objects.requireNonNull(customizer, "customizer"); | ||
} | ||
|
||
|
||
@Override | ||
@Cacheable(cacheNames = "bufferedMutator-pool", keyGenerator = "tableNameAndPoolKeyGenerator", cacheManager = "hbaseAsyncBufferedMutatorManager") | ||
public AsyncBufferedMutator getBufferedMutator(TableName tableName, ExecutorService pool) { | ||
AsyncBufferedMutatorBuilder builder = connection.getBufferedMutatorBuilder(tableName, pool); | ||
customizer.customize(builder); | ||
return builder.build(); | ||
} | ||
|
||
@Override | ||
@Cacheable(cacheNames = "bufferedMutator", keyGenerator = "tableNameAndPoolKeyGenerator", cacheManager = "hbaseAsyncBufferedMutatorManager") | ||
public AsyncBufferedMutator getBufferedMutator(TableName tableName) { | ||
AsyncBufferedMutatorBuilder builder = connection.getBufferedMutatorBuilder(tableName); | ||
customizer.customize(builder); | ||
return builder.build(); | ||
} | ||
} |
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