You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
973 B
37 lines
973 B
6 years ago
|
package db
|
||
|
|
||
|
// Code using batches should try to add this much data to the batch.
|
||
|
// The value was determined empirically.
|
||
|
const IdealBatchSize = 100 * 1024
|
||
|
|
||
|
// Putter wraps the database write operation supported by both batches and regular databases.
|
||
|
type Putter interface {
|
||
|
Put(key []byte, value []byte) error
|
||
|
}
|
||
|
|
||
|
// Deleter wraps the database delete operation supported by both batches and regular databases.
|
||
|
type Deleter interface {
|
||
|
Delete(key []byte) error
|
||
|
}
|
||
|
|
||
|
// Database wraps all database operations. All methods are safe for concurrent use.
|
||
|
type Database interface {
|
||
|
Putter
|
||
|
Deleter
|
||
|
Get(key []byte) ([]byte, error)
|
||
|
Has(key []byte) (bool, error)
|
||
|
Close()
|
||
|
NewBatch() Batch
|
||
|
}
|
||
|
|
||
|
// Batch is a write-only database that commits changes to its host database
|
||
|
// when Write is called. Batch cannot be used concurrently.
|
||
|
type Batch interface {
|
||
|
Putter
|
||
|
Deleter
|
||
|
ValueSize() int // amount of data in the batch
|
||
|
Write() error
|
||
|
// Reset resets the batch for reuse
|
||
|
Reset()
|
||
|
}
|