T
- the type of object being insertedpublic class BulkInserter<T> extends Object
BulkInserter
instances are thread safe and may be used from any
number of threads simultaneously. Use the insert(Object)
and
insert(List)
methods to queue records for insertion, and the
flush()
method to ensure that all queued records have been inserted.Modifier and Type | Class and Description |
---|---|
static class |
BulkInserter.InsertException
An exception that occurred during the insertion of records into GPUdb.
|
static class |
BulkInserter.WorkerList
Deprecated.
This class has been superceded by
com.gpudb.WorkerList . |
Constructor and Description |
---|
BulkInserter(GPUdb gpudb,
String tableName,
Type type,
int batchSize,
Map<String,String> options)
Creates a
BulkInserter with the specified parameters. |
BulkInserter(GPUdb gpudb,
String tableName,
Type type,
int batchSize,
Map<String,String> options,
WorkerList workers)
Creates a
BulkInserter with the specified parameters. |
BulkInserter(GPUdb gpudb,
String tableName,
TypeObjectMap<T> typeObjectMap,
int batchSize,
Map<String,String> options)
Creates a
BulkInserter with the specified parameters. |
BulkInserter(GPUdb gpudb,
String tableName,
TypeObjectMap<T> typeObjectMap,
int batchSize,
Map<String,String> options,
WorkerList workers)
Creates a
BulkInserter with the specified parameters. |
Modifier and Type | Method and Description |
---|---|
void |
flush()
Ensures that any queued records are inserted into GPUdb.
|
int |
getBatchSize()
Gets the batch size (the number of records to insert into GPUdb at a
time).
|
long |
getCountInserted()
Gets the number of records inserted into GPUdb.
|
long |
getCountUpdated()
Gets the number of records updated (instead of inserted) in GPUdb due to
primary key conflicts.
|
GPUdb |
getGPUdb()
Gets the GPUdb instance into which records will be inserted.
|
Map<String,String> |
getOptions()
Gets the optional parameters that will be passed to GPUdb while
inserting.
|
int |
getRetryCount()
Gets the number of times inserts into GPUdb will be retried in the event
of an error.
|
String |
getTableName()
Gets the name of the table into which records will be inserted.
|
void |
insert(List<T> records)
Queues a list of records for insertion into GPUdb.
|
void |
insert(T record)
Queues a record for insertion into GPUdb.
|
void |
setRetryCount(int value)
Sets the number of times inserts into GPUdb will be retried in the event
of an error.
|
public BulkInserter(GPUdb gpudb, String tableName, Type type, int batchSize, Map<String,String> options) throws GPUdbException
BulkInserter
with the specified parameters.gpudb
- the GPUdb instance to insert records intotableName
- the table to insert records intotype
- the type of records being insertedbatchSize
- the number of records to insert into GPUdb at a time
(records will queue until this number is reached)options
- optional parameters to pass to GPUdb while insertingGPUdbException
- if a configuration error occursIllegalArgumentException
- if an invalid parameter is specifiedInsertRecordsRequest.Options
public BulkInserter(GPUdb gpudb, String tableName, Type type, int batchSize, Map<String,String> options, WorkerList workers) throws GPUdbException
BulkInserter
with the specified parameters.gpudb
- the GPUdb instance to insert records intotableName
- name of the table to insert records intotype
- the type of records being insertedbatchSize
- the number of records to insert into GPUdb at a time
(records will queue until this number is reached); for
multi-head ingest, this value is per workeroptions
- optional parameters to pass to GPUdb while inserting
(null
for no parameters)workers
- worker list for multi-head ingest (null
to
disable multi-head ingest)GPUdbException
- if a configuration error occursIllegalArgumentException
- if an invalid parameter is specifiedInsertRecordsRequest.Options
public BulkInserter(GPUdb gpudb, String tableName, TypeObjectMap<T> typeObjectMap, int batchSize, Map<String,String> options) throws GPUdbException
BulkInserter
with the specified parameters.gpudb
- the GPUdb instance to insert records intotableName
- name of the table to insert records intotypeObjectMap
- type object map for the type of records being
insertedbatchSize
- the number of records to insert into GPUdb at a
time (records will queue until this number is
reached)options
- optional parameters to pass to GPUdb while
inserting (null
for no parameters)GPUdbException
- if a configuration error occursIllegalArgumentException
- if an invalid parameter is specifiedInsertRecordsRequest.Options
public BulkInserter(GPUdb gpudb, String tableName, TypeObjectMap<T> typeObjectMap, int batchSize, Map<String,String> options, WorkerList workers) throws GPUdbException
BulkInserter
with the specified parameters.gpudb
- the GPUdb instance to insert records intotableName
- name of the table to insert records intotypeObjectMap
- type object map for the type of records being
insertedbatchSize
- the number of records to insert into GPUdb at a
time (records will queue until this number is
reached); for multi-head ingest, this value is per
workeroptions
- optional parameters to pass to GPUdb while
inserting (null
for no parameters)workers
- worker list for multi-head ingest (null
to
disable multi-head ingest)GPUdbException
- if a configuration error occursIllegalArgumentException
- if an invalid parameter is specifiedInsertRecordsRequest.Options
public GPUdb getGPUdb()
public String getTableName()
public int getBatchSize()
public Map<String,String> getOptions()
InsertRecordsRequest.Options
public int getRetryCount()
BulkInserter.InsertException
will be
thrown.setRetryCount(int)
public void setRetryCount(int value)
BulkInserter.InsertException
will be
thrown.value
- the number of retriesIllegalArgumentException
- if value
is less than zerogetRetryCount()
public long getCountInserted()
public long getCountUpdated()
public void flush() throws BulkInserter.InsertException
BulkInserter.InsertException
to
get the list of records that were being inserted if needed (for example,
to retry). Other queues may also still contain unflushed records if
this occurs.BulkInserter.InsertException
- if an error occurs while insertingpublic void insert(T record) throws BulkInserter.InsertException
batch size
, all records in the queue will be
inserted into GPUdb before the method returns. If an error occurs while
inserting the records, the records will no longer be in the queue nor in
GPUdb; catch BulkInserter.InsertException
to get the list of records that were
being inserted if needed (for example, to retry).record
- the record to insertGPUdbException
- if an error occurs while calculating shard/primary keysBulkInserter.InsertException
- if an error occurs while insertingpublic void insert(List<T> records) throws BulkInserter.InsertException
batch size
, all records in that queue will be
inserted into GPUdb before the method returns. If an error occurs while
inserting the queued records, the records will no longer be in that queue
nor in GPUdb; catch BulkInserter.InsertException
to get the list of records
that were being inserted (including any from the queue in question and
any remaining in the list not yet queued) if needed (for example, to
retry). Note that depending on the number of records, multiple calls to
GPUdb may occur.records
- the records to insertBulkInserter.InsertException
- if an error occurs while insertingCopyright © 2020. All rights reserved.