WriteRequestBatch
in package
The WriteRequestBatch is an object that is capable of efficiently sending DynamoDB BatchWriteItem requests from queued up put and delete item requests.
requests. The batch attempts to send the requests with the fewest requests to DynamoDB as possible and also re-queues any unprocessed items to ensure that all items are sent.
Table of Contents
- $client : DynamoDbClient
- $config : array<string|int, mixed>
- $queue : array<string|int, mixed>
- __construct() : mixed
- Creates a WriteRequestBatch object that is capable of efficiently sending DynamoDB BatchWriteItem requests from queued up Put and Delete requests.
- delete() : $this
- Adds a delete item request to the batch.
- flush() : $this
- Flushes the batch by combining all the queued put and delete requests into BatchWriteItem commands and executing them. Unprocessed items are automatically re-queued.
- put() : $this
- Adds a put item request to the batch.
- autoFlush() : mixed
- If autoflush is enabled and the threshold is met, flush the batch
- determineTable() : string
- Determine the table name by looking at what was provided and what the WriteRequestBatch was originally configured with.
- prepareCommands() : array<string|int, CommandInterface>
- Creates BatchWriteItem commands from the items in the queue.
- retryUnprocessed() : mixed
- Re-queues unprocessed results with the correct data.
Properties
$client
private
DynamoDbClient
$client
DynamoDB client used to perform write operations.
$config
private
array<string|int, mixed>
$config
Configuration options for the batch.
$queue
private
array<string|int, mixed>
$queue
Queue of pending put/delete requests in the batch.
Methods
__construct()
Creates a WriteRequestBatch object that is capable of efficiently sending DynamoDB BatchWriteItem requests from queued up Put and Delete requests.
public
__construct(DynamoDbClient $client[, array<string|int, mixed> $config = [] ]) : mixed
Parameters
- $client : DynamoDbClient
-
DynamoDB client used to send batches.
- $config : array<string|int, mixed> = []
-
Batch configuration options.
- table: (string) DynamoDB table used by the batch, this can be overridden for each individual put() or delete() call.
- batch_size: (int) The size of each batch (default: 25). The batch size must be between 2 and 25. If you are sending batches of large items, you may consider lowering the batch size, otherwise, you should use 25.
- pool_size: (int) This number dictates how many BatchWriteItem requests you would like to do in parallel. For example, if the "batch_size" is 25, and "pool_size" is 3, then you would send 3 BatchWriteItem requests at a time, each with 25 items. Please keep your throughput in mind when choosing the "pool_size" option.
- autoflush: (bool) This option allows the batch to automatically flush once there are enough items (i.e., "batch_size" * "pool_size") in the queue. This defaults to true, so you must set this to false to stop autoflush.
- before: (callable) Executed before every BatchWriteItem operation. It should accept an \Aws\CommandInterface object as its argument.
- error: Executed if an error was encountered executing a, BatchWriteItem operation, otherwise errors are ignored. It should accept an \Aws\Exception\AwsException as its argument.
Tags
Return values
mixed —delete()
Adds a delete item request to the batch.
public
delete(array<string|int, mixed> $key[, string|null $table = null ]) : $this
Parameters
- $key : array<string|int, mixed>
-
Key of an item to delete. Format: [ 'key1' => ['type' => 'value'], ... ]
- $table : string|null = null
-
The name of the table. This must be specified unless the "table" option was provided in the config of the WriteRequestBatch.
Return values
$this —flush()
Flushes the batch by combining all the queued put and delete requests into BatchWriteItem commands and executing them. Unprocessed items are automatically re-queued.
public
flush([bool $untilEmpty = true ]) : $this
Parameters
- $untilEmpty : bool = true
-
If true, flushing will continue until the queue is completely empty. This will make sure that unprocessed items are all eventually sent.
Return values
$this —put()
Adds a put item request to the batch.
public
put(array<string|int, mixed> $item[, string|null $table = null ]) : $this
Parameters
- $item : array<string|int, mixed>
-
Data for an item to put. Format: [ 'attribute1' => ['type' => 'value'], 'attribute2' => ['type' => 'value'], ... ]
- $table : string|null = null
-
The name of the table. This must be specified unless the "table" option was provided in the config of the WriteRequestBatch.
Return values
$this —autoFlush()
If autoflush is enabled and the threshold is met, flush the batch
private
autoFlush() : mixed
Return values
mixed —determineTable()
Determine the table name by looking at what was provided and what the WriteRequestBatch was originally configured with.
private
determineTable(string|null $table) : string
Parameters
- $table : string|null
-
The table name.
Tags
Return values
string —prepareCommands()
Creates BatchWriteItem commands from the items in the queue.
private
prepareCommands() : array<string|int, CommandInterface>
Return values
array<string|int, CommandInterface> —retryUnprocessed()
Re-queues unprocessed results with the correct data.
private
retryUnprocessed(array<string|int, mixed> $unprocessed) : mixed
Parameters
- $unprocessed : array<string|int, mixed>
-
Unprocessed items from a result.