github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/tidb/store/localstore/engine/engine.go (about)

     1  // Copyright 2015 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package engine
    15  
    16  import "github.com/insionng/yougam/libraries/juju/errors"
    17  
    18  // ErrNotFound indicates no key is found when trying Get or Seek an entry from DB.
    19  var ErrNotFound = errors.New("local engine: key not found")
    20  
    21  // Driver is the interface that must be implemented by a local storage db engine.
    22  type Driver interface {
    23  	// Open opens or creates a local storage DB.
    24  	// The schema is a string for a local storage DB specific format.
    25  	Open(schema string) (DB, error)
    26  }
    27  
    28  // MSeekResult is used to get multiple seek results.
    29  type MSeekResult struct {
    30  	Key   []byte
    31  	Value []byte
    32  	Err   error
    33  }
    34  
    35  // DB is the interface for local storage.
    36  type DB interface {
    37  	// Get gets the associated value with key, returns (nil, ErrNotFound) if no value found.
    38  	Get(key []byte) ([]byte, error)
    39  	// Seek searches for the first key in the engine which is >= key in byte order, returns (nil, nil, ErrNotFound)
    40  	// if such key is not found.
    41  	Seek(key []byte) ([]byte, []byte, error)
    42  	// SeekReverse searches the engine in backward order for the first key-value pair which key is less than the key
    43  	// in byte order, returns (nil, nil, ErrNotFound) if such key is not found. If key is nil, the last key is returned.
    44  	SeekReverse(key []byte) ([]byte, []byte, error)
    45  	// NewBatch creates a Batch for writing.
    46  	NewBatch() Batch
    47  	// Commit writes the changed data in Batch.
    48  	Commit(b Batch) error
    49  	// Close closes database.
    50  	Close() error
    51  }
    52  
    53  // Batch is the interface for local storage.
    54  type Batch interface {
    55  	// Put appends 'put operation' of the key/value to the batch.
    56  	Put(key []byte, value []byte)
    57  	// Delete appends 'delete operation' of the key/value to the batch.
    58  	Delete(key []byte)
    59  	// Len return length of the batch
    60  	Len() int
    61  }