{"modulePath":"github.com/Evolution404/simcore","version":"v1.0.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package ethdb\n\nPackage ethdb defines the interfaces for an Ethereum data store. 定义了数据库需要使用的接口 只需要实现了这些接口就可以定义一种新的数据库 调用memorydb.New或者leveldb.New来创建一个数据库对象\n\n## Constants\n\n```go\nconst IdealBatchSize = 100 * 1024\n```\nIdealBatchSize defines the size of the data batches should ideally add in one write.\n\n## Types\n\n```go\ntype AncientBatchReader interface {\n\tAncientReader\n\n\t// ReadAncients runs the given read operation while ensuring that no writes take place\n\t// on the underlying freezer.\n\tReadAncients(fn func(AncientReader) error) (err error)\n}\n```\nAncientBatchReader is the interface for 'batched' or 'atomic' reading.\n\n```go\ntype AncientReader interface {\n\t// HasAncient returns an indicator whether the specified data exists in the\n\t// ancient store.\n\t// 判断冻结数据库中的kind表中是否有第number项数据\n\tHasAncient(kind string, number uint64) (bool, error)\n\n\t// Ancient retrieves an ancient binary blob from the append-only immutable files.\n\t// 查询冻结数据库中kind表的第number项数据\n\tAncient(kind string, number uint64) ([]byte, error)\n\n\t// AncientRange retrieves multiple items in sequence, starting from the index 'start'.\n\t// It will return\n\t//  - at most 'count' items,\n\t//  - at least 1 item (even if exceeding the maxBytes), but will otherwise\n\t//   return as many items as fit into maxBytes.\n\tAncientRange(kind string, start, count, maxBytes uint64) ([][]byte, error)\n\n\t// Ancients returns the ancient item numbers in the ancient store.\n\t// 获取冻结数据库的数据总条数\n\tAncients() (uint64, error)\n\n\t// AncientSize returns the ancient size of the specified category.\n\t// 获取冻结数据库占用的空间大小\n\tAncientSize(kind string) (uint64, error)\n}\n```\nAncientReader contains the methods required to read from immutable ancient data.\n\n```go\ntype AncientStore interface {\n\tAncientBatchReader\n\tAncientWriter\n\tio.Closer\n}\n```\nAncientStore contains all the methods required to allow handling different ancient data stores backing immutable chain data store. 旧数据的读写器\n\n```go\ntype AncientWriteOp interface {\n\t// Append adds an RLP-encoded item.\n\tAppend(kind string, number uint64, item interface{}) error\n\n\t// AppendRaw adds an item without RLP-encoding it.\n\tAppendRaw(kind string, number uint64, item []byte) error\n}\n```\nAncientWriteOp is given to the function argument of ModifyAncients. 作为ModifyAncients传入的回调函数的参数，由core/rawdb/freezer\\_batch.go文件中的freezerBatch对象实现\n\n```go\ntype AncientWriter interface {\n\t// ModifyAncients runs a write operation on the ancient store.\n\t// If the function returns an error, any changes to the underlying store are reverted.\n\t// The integer return value is the total size of the written data.\n\t// 用于向冻结数据库写入数据\n\tModifyAncients(func(AncientWriteOp) error) (int64, error)\n\n\t// TruncateAncients discards all but the first n ancient data from the ancient store.\n\t// 保留冻结数据库的前n条数据，后面的数据被删除\n\tTruncateAncients(n uint64) error\n\n\t// Sync flushes all in-memory ancient store data to disk.\n\t// 执行过写入操作要进行同步\n\tSync() error\n}\n```\nAncientWriter contains the methods required to write to immutable ancient data.\n\n```go\ntype Batch interface {\n\tKeyValueWriter\n\n\t// ValueSize retrieves the amount of data queued up for writing.\n\tValueSize() int\n\n\t// Write flushes any accumulated data to disk.\n\tWrite() error\n\n\t// Reset resets the batch for reuse.\n\tReset()\n\n\t// Replay replays the batch contents.\n\tReplay(w KeyValueWriter) error\n}\n```\nBatch is a write-only database that commits changes to its host database when Write is called. A batch cannot be used concurrently. 由Batcher.NewBatch创建的只写的数据库\n\n```go\ntype Batcher interface {\n\t// NewBatch creates a write-only database that buffers changes to its host db\n\t// until a final write is called.\n\tNewBatch() Batch\n}\n```\nBatcher wraps the NewBatch method of a backing data store. 生成一个只写的数据库\n\n```go\ntype Compacter interface {\n\t// Compact flattens the underlying data store for the given key range. In essence,\n\t// deleted and overwritten versions are discarded, and the data is rearranged to\n\t// reduce the cost of operations needed to access them.\n\t//\n\t// A nil start is treated as a key before all keys in the data store; a nil limit\n\t// is treated as a key after all keys in the data store. If both is nil then it\n\t// will compact entire data store.\n\t// start代表要压缩开始key,limit代表要压缩结束key\n\t// start=nil代表从第一个key开始压缩\n\t// limit=nil代表压缩到最后一个key\n\tCompact(start []byte, limit []byte) error\n}\n```\nCompacter wraps the Compact method of a backing data store.\n\n```go\ntype Database interface {\n\tReader\n\tWriter\n\tBatcher\n\tIteratee\n\tStater\n\tCompacter\n\tio.Closer\n}\n```\nDatabase contains all the methods required by the high level database to not only access the key-value data store but also the chain freezer. Database实现了对键值数据库和旧数据的所有操作\n\n```go\ntype HookedBatch struct {\n\tBatch\n\n\tOnPut    func(key []byte, value []byte) // Callback if a key is inserted\n\tOnDelete func(key []byte)               // Callback if a key is deleted\n}\n```\nHookedBatch wraps an arbitrary batch where each operation may be hooked into to monitor from black box code.\n\n```go\nfunc (b HookedBatch) Delete(key []byte) error\n```\nDelete removes the key from the key-value data store.\n\n```go\nfunc (b HookedBatch) Put(key []byte, value []byte) error\n```\nPut inserts the given value into the key-value data store.\n\n```go\ntype Iteratee interface {\n\t// NewIterator creates a binary-alphabetical iterator over a subset\n\t// of database content with a particular key prefix, starting at a particular\n\t// initial key (or after, if it does not exist).\n\t//\n\t// Note: This method assumes that the prefix is NOT part of the start, so there's\n\t// no need for the caller to prepend the prefix to the start\n\t// start不包含prefix\n\tNewIterator(prefix []byte, start []byte) Iterator\n}\n```\nIteratee wraps the NewIterator methods of a backing data store. 创建Iterator对象\n\n```go\ntype Iterator interface {\n\t// Next moves the iterator to the next key/value pair. It returns whether the\n\t// iterator is exhausted.\n\tNext() bool\n\n\t// Error returns any accumulated error. Exhausting all the key/value pairs\n\t// is not considered to be an error.\n\tError() error\n\n\t// Key returns the key of the current key/value pair, or nil if done. The caller\n\t// should not modify the contents of the returned slice, and its contents may\n\t// change on the next call to Next.\n\tKey() []byte\n\n\t// Value returns the value of the current key/value pair, or nil if done. The\n\t// caller should not modify the contents of the returned slice, and its contents\n\t// may change on the next call to Next.\n\tValue() []byte\n\n\t// Release releases associated resources. Release should always succeed and can\n\t// be called multiple times without causing error.\n\tRelease()\n}\n```\nIterator iterates over a database's key/value pairs in ascending key order.\n\nWhen it encounters an error any seek will return false and will yield no key/ value pairs. The error can be queried by calling the Error method. Calling Release is still necessary.\n\nAn iterator must be released after use, but it is not necessary to read an iterator until exhaustion. An iterator is not safe for concurrent use, but it is safe to use multiple iterators concurrently. 迭代器用来调用Next来挨个访问内部的键值对\n\n```go\ntype KeyValueReader interface {\n\t// Has retrieves if a key is present in the key-value data store.\n\tHas(key []byte) (bool, error)\n\n\t// Get retrieves the given key if it's present in the key-value data store.\n\tGet(key []byte) ([]byte, error)\n}\n```\nKeyValueReader wraps the Has and Get method of a backing data store.\n\n```go\ntype KeyValueStore interface {\n\tKeyValueReader\n\tKeyValueWriter\n\tBatcher\n\tIteratee\n\tStater\n\tCompacter\n\tio.Closer\n}\n```\nKeyValueStore contains all the methods required to allow handling different key-value data stores backing the high level database. 包含操作键值数据库的所有方法\n\n```go\ntype KeyValueWriter interface {\n\t// Put inserts the given value into the key-value data store.\n\tPut(key []byte, value []byte) error\n\n\t// Delete removes the key from the key-value data store.\n\tDelete(key []byte) error\n}\n```\nKeyValueWriter wraps the Put method of a backing data store.\n\n```go\ntype Reader interface {\n\tKeyValueReader\n\tAncientBatchReader\n}\n```\nReader contains the methods required to read data from both key-value as well as immutable ancient data. Reader对键值数据库和旧数据都能读\n\n```go\ntype Stater interface {\n\t// Stat returns a particular internal stat of the database.\n\tStat(property string) (string, error)\n}\n```\nStater wraps the Stat method of a backing data store.\n\n```go\ntype Writer interface {\n\tKeyValueWriter\n\tAncientWriter\n}\n```\nWriter contains the methods required to write data to both key-value as well as immutable ancient data. Writer对键值数据库和旧数据都能写\n\n","path":"github.com/Evolution404/simcore/ethdb","name":"ethdb","synopsis":"Package ethdb defines the interfaces for an Ethereum data store.","isRedistributable":true}
