public class DefaultTableStoreWriter extends Object implements TableStoreWriter
| Constructor and Description |
|---|
DefaultTableStoreWriter(AsyncClientInterface ots,
String tableName,
WriterConfig config,
TableStoreCallback<RowChange,ConsumedCapacity> callback,
Executor executor) |
DefaultTableStoreWriter(String endpoint,
ServiceCredentials credentials,
String instanceName,
String tableName,
WriterConfig config,
ClientConfiguration cc,
TableStoreCallback<RowChange,RowWriteResult> resultCallback) |
DefaultTableStoreWriter(String endpoint,
ServiceCredentials credentials,
String instanceName,
String tableName,
WriterConfig config,
TableStoreCallback<RowChange,RowWriteResult> resultCallback) |
| Modifier and Type | Method and Description |
|---|---|
void |
addRowChange(List<RowChange> rowChanges,
List<RowChange> dirtyRows)
向本地缓冲区批量写入行。
批量写入的每一行会做与
TableStoreWriter.addRowChange(RowChange)一样的检查,若批量写入的行中存在脏数据,则该函数会抛ClientException,
且所有的脏数据会写入dirtyRows。 |
void |
addRowChange(RowChange rowChange)
向本地缓冲区增加一行数据。
在写入缓冲区之前,会对该行数据做如下检查:
- 该行的主键的Schema是否与表定义的相同。
- 该行的主键列或属性列的值大小是否超过限制,值的限制配置在
WriterConfig.maxPKColumnSize和WriterConfig.maxAttrColumnSize。
- 该行的属性列的个数是否超过WriterConfig.maxColumnsCount。
- 该行的大小是否超过WriterConfig.maxBatchSize。
- 属性列中是否有列名与主键列相同。
若在写入缓冲区之前被判定为脏数据,该部分数据不会触发CallBack的调用。
以上检查会在SDK端带来额外的CPU消耗,但是这些检查是必要的,为了减少不必要的RPC开销,以及避免脏数据污染同一批次Batch写入的行。
注意:若缓冲区满,则该操作会被block。
若判断该行为脏数据,该接口会抛出ClientException。 |
Future<WriterResult> |
addRowChangeWithFuture(List<RowChange> rowChanges)
向本地缓冲区批量写入行。
批量写入的每一行会做与
TableStoreWriter.addRowChange(RowChange)一样的检查;脏数据会直接更新到WriterResponse中统计 |
Future<WriterResult> |
addRowChangeWithFuture(RowChange rowChange)
接口功能同
TableStoreWriter.addRowChange(com.alicloud.openservices.tablestore.model.RowChange)一致,
但会返回写入结果的Future,返回该行的写入成功、失败状态 |
void |
close()
关闭TableStoreWriter,在关闭之前,会先flush掉缓冲区内的所有数据。
注意:若在close过程中或者close之后仍然调用
TableStoreWriter.addRowChange(com.alicloud.openservices.tablestore.model.RowChange)向缓冲区写入数据,则该部分数据不保证会写入TableStore。
addRowChange和close两个操作之间的互斥由调用方来保证,请务必保证在调用close之前,没有任何其他线程会继续使用该writer,否则会有预期外的行为。 |
void |
flush()
主动flush缓冲区中的数据,该函数会等待缓冲区中的所有数据被flush完毕。
注意:若在调用flush之后继续向缓冲区中写入数据,flush不会等待这部分新数据的写入,新数据的flush需要重新调用一次flush。
|
TableStoreCallback<RowChange,ConsumedCapacity> |
getCallback() |
TableStoreCallback<RowChange,RowWriteResult> |
getResultCallback()
获取设置的Callback。
|
WriterConfig |
getWriterConfig()
获取限制项配置。
|
WriterStatistics |
getWriterStatistics()
获取数据导入期间的统计信息。
|
void |
setCallback(TableStoreCallback<RowChange,ConsumedCapacity> callback) |
void |
setResultCallback(TableStoreCallback<RowChange,RowWriteResult> resultCallback)
设置Callback,数据写入成功或者失败均会通过Callback来反馈。
注意:callback会被写入TableStoreWriter的所有行共享,会被并发的调用。
这与
AsyncClientInterface中每个接口的Callback不同,其callback会与每个请求一一对应,且可以是独立的。
但是这里的Callback是与RowChange对应,且所有RowChange都共享该callback。 |
void |
startFlushTimer(int flushInterval) |
boolean |
tryAddRowChange(RowChange rowChange)
Same with
TableStoreWriter.addRowChange(RowChange), but it won't be blocked if the buffer is full. |
public DefaultTableStoreWriter(AsyncClientInterface ots, String tableName, WriterConfig config, TableStoreCallback<RowChange,ConsumedCapacity> callback, Executor executor)
public DefaultTableStoreWriter(String endpoint, ServiceCredentials credentials, String instanceName, String tableName, WriterConfig config, TableStoreCallback<RowChange,RowWriteResult> resultCallback)
public DefaultTableStoreWriter(String endpoint, ServiceCredentials credentials, String instanceName, String tableName, WriterConfig config, ClientConfiguration cc, TableStoreCallback<RowChange,RowWriteResult> resultCallback)
public void addRowChange(RowChange rowChange)
TableStoreWriterWriterConfig.maxPKColumnSize和WriterConfig.maxAttrColumnSize。
- 该行的属性列的个数是否超过WriterConfig.maxColumnsCount。
- 该行的大小是否超过WriterConfig.maxBatchSize。
- 属性列中是否有列名与主键列相同。
若在写入缓冲区之前被判定为脏数据,该部分数据不会触发CallBack的调用。
以上检查会在SDK端带来额外的CPU消耗,但是这些检查是必要的,为了减少不必要的RPC开销,以及避免脏数据污染同一批次Batch写入的行。
注意:若缓冲区满,则该操作会被block。
若判断该行为脏数据,该接口会抛出ClientException。addRowChange in interface TableStoreWriterrowChange - 要写入的行public Future<WriterResult> addRowChangeWithFuture(RowChange rowChange)
TableStoreWriterTableStoreWriter.addRowChange(com.alicloud.openservices.tablestore.model.RowChange)一致,
但会返回写入结果的Future,返回该行的写入成功、失败状态addRowChangeWithFuture in interface TableStoreWriterrowChange - 要写入的行public boolean tryAddRowChange(RowChange rowChange)
TableStoreWriterTableStoreWriter.addRowChange(RowChange), but it won't be blocked if the buffer is full.tryAddRowChange in interface TableStoreWriterpublic void startFlushTimer(int flushInterval)
public void addRowChange(List<RowChange> rowChanges, List<RowChange> dirtyRows) throws ClientException
TableStoreWriterTableStoreWriter.addRowChange(RowChange)一样的检查,若批量写入的行中存在脏数据,则该函数会抛ClientException,
且所有的脏数据会写入dirtyRows。addRowChange in interface TableStoreWriterrowChanges - 批量写入的行dirtyRows - 用于传出脏数据的列表ClientException - 若存在脏数据public Future<WriterResult> addRowChangeWithFuture(List<RowChange> rowChanges) throws ClientException
TableStoreWriterTableStoreWriter.addRowChange(RowChange)一样的检查;脏数据会直接更新到WriterResponse中统计addRowChangeWithFuture in interface TableStoreWriterrowChanges - 批量写入的行ClientException - 若存在脏数据public void setCallback(TableStoreCallback<RowChange,ConsumedCapacity> callback)
setCallback in interface TableStoreWriterTableStoreWriter.setResultCallback(TableStoreCallback)public void setResultCallback(TableStoreCallback<RowChange,RowWriteResult> resultCallback)
TableStoreWriterAsyncClientInterface中每个接口的Callback不同,其callback会与每个请求一一对应,且可以是独立的。
但是这里的Callback是与RowChange对应,且所有RowChange都共享该callback。setResultCallback in interface TableStoreWriterpublic TableStoreCallback<RowChange,ConsumedCapacity> getCallback()
getCallback in interface TableStoreWriterTableStoreWriter.getResultCallback()public TableStoreCallback<RowChange,RowWriteResult> getResultCallback()
TableStoreWritergetResultCallback in interface TableStoreWriterpublic WriterConfig getWriterConfig()
TableStoreWritergetWriterConfig in interface TableStoreWriterpublic WriterStatistics getWriterStatistics()
TableStoreWritergetWriterStatistics in interface TableStoreWriterpublic void flush()
throws ClientException
TableStoreWriterflush in interface TableStoreWriterClientExceptionpublic void close()
TableStoreWriterTableStoreWriter.addRowChange(com.alicloud.openservices.tablestore.model.RowChange)向缓冲区写入数据,则该部分数据不保证会写入TableStore。
addRowChange和close两个操作之间的互斥由调用方来保证,请务必保证在调用close之前,没有任何其他线程会继续使用该writer,否则会有预期外的行为。close in interface TableStoreWriterCopyright © 2024. All Rights Reserved.