2016-05-13 06:50:33 +03:00
|
|
|
// Copyright 2015 The etcd Authors
|
2015-09-15 23:54:11 +03:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2016-04-25 22:32:58 +03:00
|
|
|
package mvcc
|
2015-05-15 06:25:52 +03:00
|
|
|
|
2015-06-08 19:26:56 +03:00
|
|
|
import (
|
2016-01-05 21:16:50 +03:00
|
|
|
"github.com/coreos/etcd/lease"
|
2016-04-25 22:32:58 +03:00
|
|
|
"github.com/coreos/etcd/mvcc/backend"
|
|
|
|
"github.com/coreos/etcd/mvcc/mvccpb"
|
2015-06-08 19:26:56 +03:00
|
|
|
)
|
2015-05-15 06:25:52 +03:00
|
|
|
|
2015-05-21 22:03:58 +03:00
|
|
|
type KV interface {
|
2015-09-15 22:11:00 +03:00
|
|
|
// Rev returns the current revision of the KV.
|
|
|
|
Rev() int64
|
|
|
|
|
2016-01-26 05:39:08 +03:00
|
|
|
// FirstRev returns the first revision of the KV.
|
|
|
|
// After a compaction, the first revision increases to the compaction
|
|
|
|
// revision.
|
|
|
|
FirstRev() int64
|
|
|
|
|
2015-05-31 08:56:33 +03:00
|
|
|
// Range gets the keys in the range at rangeRev.
|
2016-01-31 03:51:12 +03:00
|
|
|
// The returned rev is the current revision of the KV when the operation is executed.
|
2015-05-31 08:56:33 +03:00
|
|
|
// If rangeRev <=0, range gets the keys at currentRev.
|
2015-05-21 22:03:58 +03:00
|
|
|
// If `end` is nil, the request returns the key.
|
2016-02-12 20:43:39 +03:00
|
|
|
// If `end` is not nil and not empty, it gets the keys in range [key, range_end).
|
|
|
|
// If `end` is not nil and empty, it gets the keys greater than or equal to key.
|
2015-05-21 22:03:58 +03:00
|
|
|
// Limit limits the number of keys returned.
|
2015-05-31 18:59:31 +03:00
|
|
|
// If the required rev is compacted, ErrCompacted will be returned.
|
2016-04-25 22:32:58 +03:00
|
|
|
Range(key, end []byte, limit, rangeRev int64) (kvs []mvccpb.KeyValue, rev int64, err error)
|
2015-05-21 22:03:58 +03:00
|
|
|
|
2016-01-05 02:12:59 +03:00
|
|
|
// Put puts the given key, value into the store. Put also takes additional argument lease to
|
|
|
|
// attach a lease to a key-value pair as meta-data. KV implementation does not validate the lease
|
|
|
|
// id.
|
2015-05-31 08:56:33 +03:00
|
|
|
// A put also increases the rev of the store, and generates one event in the event history.
|
2016-01-31 03:51:12 +03:00
|
|
|
// The returned rev is the current revision of the KV when the operation is executed.
|
2016-01-05 21:16:50 +03:00
|
|
|
Put(key, value []byte, lease lease.LeaseID) (rev int64)
|
2015-05-21 22:03:58 +03:00
|
|
|
|
|
|
|
// DeleteRange deletes the given range from the store.
|
2015-05-31 08:56:33 +03:00
|
|
|
// A deleteRange increases the rev of the store if any key in the range exists.
|
2015-05-21 22:03:58 +03:00
|
|
|
// The number of key deleted will be returned.
|
2016-01-31 03:51:12 +03:00
|
|
|
// The returned rev is the current revision of the KV when the operation is executed.
|
2015-05-21 22:03:58 +03:00
|
|
|
// It also generates one event for each key delete in the event history.
|
|
|
|
// if the `end` is nil, deleteRange deletes the key.
|
|
|
|
// if the `end` is not nil, deleteRange deletes the keys in range [key, range_end).
|
2015-05-31 08:56:33 +03:00
|
|
|
DeleteRange(key, end []byte) (n, rev int64)
|
2015-05-21 22:03:58 +03:00
|
|
|
|
2015-07-24 18:16:27 +03:00
|
|
|
// TxnBegin begins a txn. Only Txn prefixed operation can be executed, others will be blocked
|
|
|
|
// until txn ends. Only one on-going txn is allowed.
|
|
|
|
// TxnBegin returns an int64 txn ID.
|
|
|
|
// All txn prefixed operations with same txn ID will be done with the same rev.
|
|
|
|
TxnBegin() int64
|
|
|
|
// TxnEnd ends the on-going txn with txn ID. If the on-going txn ID is not matched, error is returned.
|
|
|
|
TxnEnd(txnID int64) error
|
2016-01-31 03:51:12 +03:00
|
|
|
// TxnRange returns the current revision of the KV when the operation is executed.
|
2016-04-25 22:32:58 +03:00
|
|
|
TxnRange(txnID int64, key, end []byte, limit, rangeRev int64) (kvs []mvccpb.KeyValue, rev int64, err error)
|
2016-01-05 21:16:50 +03:00
|
|
|
TxnPut(txnID int64, key, value []byte, lease lease.LeaseID) (rev int64, err error)
|
2015-07-24 18:16:27 +03:00
|
|
|
TxnDeleteRange(txnID int64, key, end []byte) (n, rev int64, err error)
|
2015-05-31 18:59:31 +03:00
|
|
|
|
2016-04-14 05:59:26 +03:00
|
|
|
// Compact frees all superseded keys with revisions less than rev.
|
2016-03-29 02:07:56 +03:00
|
|
|
Compact(rev int64) (<-chan struct{}, error)
|
2015-06-08 19:26:56 +03:00
|
|
|
|
2016-05-03 00:37:56 +03:00
|
|
|
// Hash retrieves the hash of KV state and revision.
|
2015-09-14 07:29:10 +03:00
|
|
|
// This method is designed for consistency checking purpose.
|
2016-05-03 00:37:56 +03:00
|
|
|
Hash() (hash uint32, revision int64, err error)
|
2015-09-14 07:29:10 +03:00
|
|
|
|
2015-10-27 07:06:08 +03:00
|
|
|
// Commit commits txns into the underlying backend.
|
|
|
|
Commit()
|
|
|
|
|
2016-01-07 03:25:25 +03:00
|
|
|
// Restore restores the KV store from a backend.
|
|
|
|
Restore(b backend.Backend) error
|
2015-06-08 19:26:56 +03:00
|
|
|
Close() error
|
2015-05-21 22:03:58 +03:00
|
|
|
}
|
2015-09-09 19:49:28 +03:00
|
|
|
|
|
|
|
// WatchableKV is a KV that can be watched.
|
|
|
|
type WatchableKV interface {
|
|
|
|
KV
|
2015-11-04 02:57:35 +03:00
|
|
|
Watchable
|
|
|
|
}
|
2015-09-09 19:49:28 +03:00
|
|
|
|
2016-01-03 02:59:32 +03:00
|
|
|
// Watchable is the interface that wraps the NewWatchStream function.
|
2015-11-04 02:57:35 +03:00
|
|
|
type Watchable interface {
|
2016-01-03 02:59:32 +03:00
|
|
|
// NewWatchStream returns a WatchStream that can be used to
|
2016-01-08 11:21:19 +03:00
|
|
|
// watch events happened or happening on the KV.
|
2016-01-03 02:59:32 +03:00
|
|
|
NewWatchStream() WatchStream
|
2015-09-09 19:49:28 +03:00
|
|
|
}
|
2015-10-21 21:08:19 +03:00
|
|
|
|
|
|
|
// ConsistentWatchableKV is a WatchableKV that understands the consistency
|
|
|
|
// algorithm and consistent index.
|
2015-10-27 07:42:49 +03:00
|
|
|
// If the consistent index of executing entry is not larger than the
|
|
|
|
// consistent index of ConsistentWatchableKV, all operations in
|
|
|
|
// this entry are skipped and return empty response.
|
2015-10-21 21:08:19 +03:00
|
|
|
type ConsistentWatchableKV interface {
|
|
|
|
WatchableKV
|
2016-03-30 21:37:55 +03:00
|
|
|
// ConsistentIndex returns the current consistent index of the KV.
|
|
|
|
ConsistentIndex() uint64
|
2015-10-21 21:08:19 +03:00
|
|
|
}
|