fabric: github.com/hyperledger/fabric/core/ledger/util/couchdb Index | Files

package couchdb

import "github.com/hyperledger/fabric/core/ledger/util/couchdb"


Package Files

couchdb.go couchdbutil.go metrics.go

func ConstructMetadataDBName Uses

func ConstructMetadataDBName(dbName string) string

ConstructMetadataDBName truncates the db name to couchdb allowed length to construct the metadataDBName

func ConstructNamespaceDBName Uses

func ConstructNamespaceDBName(chainName, namespace string) string

ConstructNamespaceDBName truncates db name to couchdb allowed length to construct the final namespaceDBName The passed namespace will be in one of the following formats: <chaincode> - for namespaces containing regular public data <chaincode>$$p<collection> - for namespaces containing private data collections <chaincode>$$h<collection> - for namespaces containing hashes of private data collections

func CreateSystemDatabasesIfNotExist Uses

func CreateSystemDatabasesIfNotExist(couchInstance *CouchInstance) error

CreateSystemDatabasesIfNotExist - creates the system databases if they do not exist

func IsJSON Uses

func IsJSON(s string) bool

IsJSON tests a string to determine if a valid JSON

type AttachmentInfo Uses

type AttachmentInfo struct {
    Name            string
    ContentType     string `json:"content_type"`
    Length          uint64
    AttachmentBytes []byte `json:"data"`

AttachmentInfo contains the definition for an attached file for couchdb

type Base64Attachment Uses

type Base64Attachment struct {
    ContentType    string `json:"content_type"`
    AttachmentData string `json:"data"`

Base64Attachment contains the definition for an attached file for couchdb

type BatchRetrieveDocMetadataResponse Uses

type BatchRetrieveDocMetadataResponse struct {
    Rows []struct {
        ID          string `json:"id"`
        DocMetadata struct {
            ID      string `json:"_id"`
            Rev     string `json:"_rev"`
            Version string `json:"~version"`
        }   `json:"doc"`
    } `json:"rows"`

BatchRetrieveDocMetadataResponse is used for processing REST batch responses from CouchDB

type BatchUpdateResponse Uses

type BatchUpdateResponse struct {
    ID     string `json:"id"`
    Error  string `json:"error"`
    Reason string `json:"reason"`
    Ok     bool   `json:"ok"`
    Rev    string `json:"rev"`

BatchUpdateResponse defines a structure for batch update response

type Config Uses

type Config struct {
    // Address is the hostname:port of the CouchDB database instance.
    Address string
    // Username is the username used to authenticate with CouchDB.  This username
    // must have read and write access permissions.
    Username string
    // Password is the password for Username.
    Password string
    // MaxRetries is the maximum number of times to retry CouchDB operations on
    // failure.
    MaxRetries int
    // MaxRetriesOnStartup is the maximum number of times to retry CouchDB operations on
    // failure when initializing the ledger.
    MaxRetriesOnStartup int
    // RequestTimeout is the timeout used for CouchDB operations.
    RequestTimeout time.Duration
    // InternalQueryLimit is the maximum number of records to return internally
    // when querying CouchDB.
    InternalQueryLimit int
    // MaxBatchUpdateSize is the maximum number of records to included in CouchDB
    // bulk update operations.
    MaxBatchUpdateSize int
    // WarmIndexesAfterNBlocks is the number of blocks after which to warm any
    // CouchDB indexes.
    WarmIndexesAfterNBlocks int
    // CreateGlobalChangesDB determines whether or not to create the "_global_changes"
    // system database.
    CreateGlobalChangesDB bool
    // RedoLogPath is the directory where the CouchDB redo log files are stored.
    RedoLogPath string
    // UserCacheSizeMBs denotes the user specified maximum mega bytes (MB) to be allocated
    // for the user state cache (i.e., all chaincodes deployed by the user). Note that
    // UserCacheSizeMBs needs to be a multiple of 32 MB. If it is not a multiple of 32 MB,
    // the peer would round the size to the next multiple of 32 MB.
    UserCacheSizeMBs int

Config is a structure used to configure a CouchInstance.

type ConnectionInfo Uses

type ConnectionInfo struct {
    Couchdb string `json:"couchdb"`
    Version string `json:"version"`
    Vendor  struct {
        Name string `json:"name"`
    }   `json:"vendor"`

ConnectionInfo is a structure for capturing the database info and version

type CouchDatabase Uses

type CouchDatabase struct {
    CouchInstance    *CouchInstance //connection configuration
    DBName           string
    IndexWarmCounter int

CouchDatabase represents a database within a CouchDB instance

func CreateCouchDatabase Uses

func CreateCouchDatabase(couchInstance *CouchInstance, dbName string) (*CouchDatabase, error)

CreateCouchDatabase creates a CouchDB database object, as well as the underlying database if it does not exist

func (*CouchDatabase) ApplyDatabaseSecurity Uses

func (dbclient *CouchDatabase) ApplyDatabaseSecurity(databaseSecurity *DatabaseSecurity) error

ApplyDatabaseSecurity method provides function to update the security config for a database

func (*CouchDatabase) BatchRetrieveDocumentMetadata Uses

func (dbclient *CouchDatabase) BatchRetrieveDocumentMetadata(keys []string) ([]*DocMetadata, error)

BatchRetrieveDocumentMetadata - batch method to retrieve document metadata for a set of keys, including ID, couchdb revision number, and ledger version

func (*CouchDatabase) BatchUpdateDocuments Uses

func (dbclient *CouchDatabase) BatchUpdateDocuments(documents []*CouchDoc) ([]*BatchUpdateResponse, error)

BatchUpdateDocuments - batch method to batch update documents

func (*CouchDatabase) CreateDatabaseIfNotExist Uses

func (dbclient *CouchDatabase) CreateDatabaseIfNotExist() error

CreateDatabaseIfNotExist method provides function to create database

func (*CouchDatabase) CreateIndex Uses

func (dbclient *CouchDatabase) CreateIndex(indexdefinition string) (*CreateIndexResponse, error)

CreateIndex method provides a function creating an index

func (*CouchDatabase) DeleteDoc Uses

func (dbclient *CouchDatabase) DeleteDoc(id, rev string) error

DeleteDoc method provides function to delete a document from the database by id

func (*CouchDatabase) DeleteIndex Uses

func (dbclient *CouchDatabase) DeleteIndex(designdoc, indexname string) error

DeleteIndex method provides a function deleting an index

func (*CouchDatabase) DropDatabase Uses

func (dbclient *CouchDatabase) DropDatabase() (*DBOperationResponse, error)

DropDatabase provides method to drop an existing database

func (*CouchDatabase) EnsureFullCommit Uses

func (dbclient *CouchDatabase) EnsureFullCommit() (*DBOperationResponse, error)

EnsureFullCommit calls _ensure_full_commit for explicit fsync

func (*CouchDatabase) GetDatabaseInfo Uses

func (dbclient *CouchDatabase) GetDatabaseInfo() (*DBInfo, *DBReturn, error)

GetDatabaseInfo method provides function to retrieve database information

func (*CouchDatabase) GetDatabaseSecurity Uses

func (dbclient *CouchDatabase) GetDatabaseSecurity() (*DatabaseSecurity, error)

GetDatabaseSecurity method provides function to retrieve the security config for a database

func (*CouchDatabase) ListIndex Uses

func (dbclient *CouchDatabase) ListIndex() ([]*IndexResult, error)

ListIndex method lists the defined indexes for a database

func (*CouchDatabase) QueryDocuments Uses

func (dbclient *CouchDatabase) QueryDocuments(query string) ([]*QueryResult, string, error)

QueryDocuments method provides function for processing a query

func (*CouchDatabase) ReadDoc Uses

func (dbclient *CouchDatabase) ReadDoc(id string) (*CouchDoc, string, error)

ReadDoc method provides function to retrieve a document and its revision from the database by id

func (*CouchDatabase) ReadDocRange Uses

func (dbclient *CouchDatabase) ReadDocRange(startKey, endKey string, limit int32) ([]*QueryResult, string, error)

ReadDocRange method provides function to a range of documents based on the start and end keys startKey and endKey can also be empty strings. If startKey and endKey are empty, all documents are returned This function provides a limit option to specify the max number of entries and is supplied by config. Skip is reserved for possible future future use.

func (*CouchDatabase) SaveDoc Uses

func (dbclient *CouchDatabase) SaveDoc(id string, rev string, couchDoc *CouchDoc) (string, error)

SaveDoc method provides a function to save a document, id and byte array

func (*CouchDatabase) WarmIndex Uses

func (dbclient *CouchDatabase) WarmIndex(designdoc, indexname string) error

WarmIndex method provides a function for warming a single index

func (*CouchDatabase) WarmIndexAllIndexes Uses

func (dbclient *CouchDatabase) WarmIndexAllIndexes() error

WarmIndexAllIndexes method provides a function for warming all indexes for a database

type CouchDoc Uses

type CouchDoc struct {
    JSONValue   []byte
    Attachments []*AttachmentInfo

CouchDoc defines the structure for a JSON document value

type CouchInstance Uses

type CouchInstance struct {
    // contains filtered or unexported fields

CouchInstance represents a CouchDB instance

func CreateCouchInstance Uses

func CreateCouchInstance(config *Config, metricsProvider metrics.Provider) (*CouchInstance, error)

func (*CouchInstance) HealthCheck Uses

func (couchInstance *CouchInstance) HealthCheck(ctx context.Context) error

HealthCheck checks if the peer is able to communicate with CouchDB

func (*CouchInstance) InternalQueryLimit Uses

func (couchInstance *CouchInstance) InternalQueryLimit() int32

InternalQueryLimit returns the maximum number of records to return internally when querying CouchDB.

func (*CouchInstance) IsEmpty Uses

func (couchInstance *CouchInstance) IsEmpty(databasesToIgnore []string) (bool, error)

IsEmpty returns false if couchInstance contains any databases (except couchdb system databases and any database name supplied in the parameter 'databasesToIgnore')

func (*CouchInstance) MaxBatchUpdateSize Uses

func (couchInstance *CouchInstance) MaxBatchUpdateSize() int

MaxBatchUpdateSize returns the maximum number of records to include in a bulk update operation.

func (*CouchInstance) RetrieveApplicationDBNames Uses

func (couchInstance *CouchInstance) RetrieveApplicationDBNames() ([]string, error)

RetrieveApplicationDBNames returns all the applicaiton database names in the couch instance

func (*CouchInstance) URL Uses

func (couchInstance *CouchInstance) URL() string

URL returns the URL for the CouchDB instance.

func (*CouchInstance) VerifyCouchConfig Uses

func (couchInstance *CouchInstance) VerifyCouchConfig() (*ConnectionInfo, *DBReturn, error)

VerifyCouchConfig method provides function to verify the connection information

type CreateIndexResponse Uses

type CreateIndexResponse struct {
    Result string `json:"result"`
    ID     string `json:"id"`
    Name   string `json:"name"`

CreateIndexResponse contains an the index creation response from CouchDB

type DBInfo Uses

type DBInfo struct {
    DbName string `json:"db_name"`
    Sizes  struct {
        File     int `json:"file"`
        External int `json:"external"`
        Active   int `json:"active"`
    }   `json:"sizes"`
    Other struct {
        DataSize int `json:"data_size"`
    }   `json:"other"`
    DocDelCount       int    `json:"doc_del_count"`
    DocCount          int    `json:"doc_count"`
    DiskSize          int    `json:"disk_size"`
    DiskFormatVersion int    `json:"disk_format_version"`
    DataSize          int    `json:"data_size"`
    CompactRunning    bool   `json:"compact_running"`
    InstanceStartTime string `json:"instance_start_time"`

DBInfo is body for database information.

type DBOperationResponse Uses

type DBOperationResponse struct {
    Ok bool

DBOperationResponse is body for successful database calls.

type DBReturn Uses

type DBReturn struct {
    StatusCode int    `json:"status_code"`
    Error      string `json:"error"`
    Reason     string `json:"reason"`

DBReturn contains an error reported by CouchDB

type DatabaseSecurity Uses

type DatabaseSecurity struct {
    Admins struct {
        Names []string `json:"names"`
        Roles []string `json:"roles"`
    }   `json:"admins"`
    Members struct {
        Names []string `json:"names"`
        Roles []string `json:"roles"`
    }   `json:"members"`

DatabaseSecurity contains the definition for CouchDB database security

type DocID Uses

type DocID struct {
    ID string `json:"_id"`

DocID is a minimal structure for capturing the ID from a query result

type DocMetadata Uses

type DocMetadata struct {
    ID              string                     `json:"_id"`
    Rev             string                     `json:"_rev"`
    Version         string                     `json:"~version"`
    AttachmentsInfo map[string]*AttachmentInfo `json:"_attachments"`

DocMetadata is used for capturing CouchDB document header info, used to capture id, version, rev and attachments returned in the query from CouchDB

type FileDetails Uses

type FileDetails struct {
    Follows     bool   `json:"follows"`
    ContentType string `json:"content_type"`
    Length      int    `json:"length"`

FileDetails defines the structure needed to send an attachment to couchdb

type IndexResult Uses

type IndexResult struct {
    DesignDocument string `json:"designdoc"`
    Name           string `json:"name"`
    Definition     string `json:"definition"`

IndexResult contains the definition for a couchdb index

type QueryResponse Uses

type QueryResponse struct {
    Warning  string            `json:"warning"`
    Docs     []json.RawMessage `json:"docs"`
    Bookmark string            `json:"bookmark"`

QueryResponse is used for processing REST query responses from CouchDB

type QueryResult Uses

type QueryResult struct {
    ID          string
    Value       []byte
    Attachments []*AttachmentInfo

QueryResult is used for returning query results from CouchDB

type RangeQueryResponse Uses

type RangeQueryResponse struct {
    TotalRows int32 `json:"total_rows"`
    Offset    int32 `json:"offset"`
    Rows      []struct {
        ID    string `json:"id"`
        Key   string `json:"key"`
        Value struct {
            Rev string `json:"rev"`
        }   `json:"value"`
        Doc json.RawMessage `json:"doc"`
    }   `json:"rows"`

RangeQueryResponse is used for processing REST range query responses from CouchDB

Package couchdb imports 27 packages (graph) and is imported by 7 packages. Updated 2020-01-17. Refresh now. Tools for package owners.