2014-09-19 09:18:44 -07:00
|
|
|
// Copyright 2014 Prometheus Team
|
|
|
|
// 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.
|
|
|
|
|
2014-08-21 13:06:11 -07:00
|
|
|
package index
|
|
|
|
|
2014-09-10 09:41:52 -07:00
|
|
|
import "encoding"
|
2014-08-21 13:06:11 -07:00
|
|
|
|
2014-09-16 06:47:24 -07:00
|
|
|
// KeyValueStore persists key/value pairs. Implementations must be fundamentally
|
|
|
|
// goroutine-safe. However, it is the caller's responsibility that keys and
|
|
|
|
// values can be safely marshaled and unmarshaled (via the MarshalBinary and
|
|
|
|
// UnmarshalBinary methods of the keys and values). For example, if you call the
|
|
|
|
// Put method of a KeyValueStore implementation, but the key or the value are
|
|
|
|
// modified concurrently while being marshaled into its binary representation,
|
|
|
|
// you obviously have a problem. Methods of KeyValueStore only return after
|
|
|
|
// (un)marshaling is complete.
|
2014-08-21 13:06:11 -07:00
|
|
|
type KeyValueStore interface {
|
2014-09-09 05:36:26 -07:00
|
|
|
Put(key, value encoding.BinaryMarshaler) error
|
2014-09-16 06:47:24 -07:00
|
|
|
// Get unmarshals the result into value. It returns false if no entry
|
|
|
|
// could be found for key. If value is nil, Get behaves like Has.
|
|
|
|
Get(key encoding.BinaryMarshaler, value encoding.BinaryUnmarshaler) (bool, error)
|
|
|
|
Has(key encoding.BinaryMarshaler) (bool, error)
|
|
|
|
// Delete returns an error if key does not exist.
|
|
|
|
Delete(key encoding.BinaryMarshaler) error
|
2014-08-21 13:06:11 -07:00
|
|
|
|
|
|
|
NewBatch() Batch
|
|
|
|
Commit(b Batch) error
|
2014-09-18 08:14:14 -07:00
|
|
|
ForEach(func(kv KeyValueAccessor) error) error
|
2014-08-21 13:06:11 -07:00
|
|
|
|
|
|
|
Close() error
|
|
|
|
}
|
|
|
|
|
2014-09-16 06:47:24 -07:00
|
|
|
// Batch allows KeyValueStore mutations to be pooled and committed together. An
|
|
|
|
// implementation does not have to be goroutine-safe. Never modify a Batch
|
|
|
|
// concurrently or commit the same batch multiple times concurrently. Marshaling
|
|
|
|
// of keys and values is guaranteed to be complete when the Put or Delete methods
|
|
|
|
// have returned.
|
2014-08-21 13:06:11 -07:00
|
|
|
type Batch interface {
|
2014-09-09 05:36:26 -07:00
|
|
|
Put(key, value encoding.BinaryMarshaler) error
|
|
|
|
Delete(key encoding.BinaryMarshaler) error
|
2014-08-21 13:06:11 -07:00
|
|
|
Reset()
|
|
|
|
}
|