instruction

package
v0.0.0-...-c772d2a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CreateCollection string = "create_collection"
	UpdateCollection string = "update_collection"
	Insert           string = "insert"
	Update           string = "update"
	Delete           string = "delete"
	CreateIndex      string = "hint_create_index"
	DropIndex        string = "hint_drop_index"

	CommandCollection string = "_op"
	MasterCollection  string = "_master"
)

Variables

View Source
var (
	DataType     = "data"     // for actual data storage
	HistoryType  = "history"  // data history versions
	OpRecordType = "oprecord" //
	DocInfoType  = "info"     // document info

)
View Source
var NamePattern = map[string]string{
	DataType:     "%s_" + DataType,
	HistoryType:  "%s_" + HistoryType,
	OpRecordType: "%s_" + OpRecordType,
	DocInfoType:  "%s_" + DocInfoType,
}

Functions

func Audit

func Audit(op string, hash string, coll string, timestamp string, data map[string]interface{}, pk string, sig string) error

func HistoryRecord

func HistoryRecord(op string, hash string, version int, coll string, timestamp string, data map[string]interface{}, pk string, sig string) error

func InsertInfo

func InsertInfo(hash string, coll string, pubkey string, timestamp string) (int, error)

func OpRecord

func OpRecord(op string, version int, hash string, coll string, timestamp string, data map[string]interface{}, pk string, sig string) error

func UpdateInfo

func UpdateInfo(hash string) (int, error)

Types

type AuditModel

type AuditModel struct {
	OpHash string `json:"_id"` //数据的hash
	//Collection string                 `json:"collection"` //操作的数据表
	Operation string                 `json:"operation"`
	Timestamp string                 `json:"timestamp"`
	Data      map[string]interface{} `json:"data"`       //操作记录
	PublicKey string                 `json:"public_key"` //公钥
	Signature string                 `json:"signature"`  //签名
}

Audit table. merged to oprecord

type CollectionCommand

type CollectionCommand struct {
	//OpHash     string                 `json:"op_hash"`    //产生数据的hash作为主键
	Op         string            `json:"op"`
	Collection string            `json:"collection"` //要操作的数据表
	Feature    CollectionFeature `json:"feature"`
	PublicKey  string            `json:"public_key"` //公钥
}

type CollectionFeature

type CollectionFeature struct {
	AllowUpdate        bool     `json:"allow_update"`
	AllowDelete        bool     `json:"allow_delete"`
	Cooperate          bool     `json:"cooperate"`
	AllowInsertMembers []string `json:"allow_insert_members"`
	AllowUpdateMembers []string `json:"allow_update_members"`
	AllowDeleteMembers []string `json:"allow_delete_members"`
}

type DeleteCommand

type DeleteCommand struct {
	//OpHash     string            `json:"op_hash"`
	Op         string            `json:"op"`
	Collection string            `json:"collection"` //要操作的数据表
	Query      map[string]string `json:"query"`
	PublicKey  string            `json:"public_key"` //公钥
}

type DocInfoDoc

type DocInfoDoc struct {
	DocId   string `json:"doc_id"` // 文档Id
	Version int    `json:"version"`
	//Collection   string `json:"collection"` //操作的数据表
	CreatedAt  int64  `json:"created_at"` // timestamp ms
	CreatedBy  string `json:"created_by"`
	ModifiedAt int64  `json:"modified_at"` // timestamp ms
	ModifiedBy string `json:"modified_by"`
}

info table

type GeneralCommand

type GeneralCommand struct {
	TxHash    string `json:"tx_hash"`
	OpHash    string `json:"op_hash"`
	OpStr     string `json:"op_str"`
	Signature string `json:"signature"`
	PublicKey string `json:"public_key"`
}

type HistoryDoc

type HistoryDoc struct {
	DocId   string `json:"doc_id"` // 文档Id
	Version int    `json:"version"`
	//Collection string                 `json:"collection"` //操作的数据表
	Timestamp string                 `json:"timestamp"`
	Data      map[string]interface{} `json:"history"`    //历史版本
	PublicKey string                 `json:"public_key"` //公钥
	Signature string                 `json:"signature"`  //签名
}

history table。

func GetHistoryRecord

func GetHistoryRecord(hash string, coll string) []HistoryDoc

type IndexCommand

type IndexCommand struct {
	//OpHash     string            `json:"op_hash"`
	Op         string            `json:"op"`
	Collection string            `json:"collection"` //要操作的数据表
	Index      map[string]string `json:"index"`
	PublicKey  string            `json:"public_key"` //公钥
}

type InsertCommand

type InsertCommand struct {
	//OpHash     string                 `json:"op_hash"`    //产生数据的hash作为主键
	Op         string                 `json:"op"`
	Collection string                 `json:"collection"` //要操作的数据表
	Data       map[string]interface{} `json:"data"`
	PublicKey  string                 `json:"public_key"` //公钥
}

type InstructionExecutor

type InstructionExecutor struct {
	Config InstructionExecutorConfig
	// contains filtered or unexported fields
}

func (*InstructionExecutor) Execute

func (t *InstructionExecutor) Execute(command GeneralCommand) (err error)

func (*InstructionExecutor) InitCollection

func (t *InstructionExecutor) InitCollection(ctx context.Context, collName string) (err error)

InitCollection setup all necessary collections to support business

func (*InstructionExecutor) InitDefault

func (t *InstructionExecutor) InitDefault()

func (*InstructionExecutor) Name

func (t *InstructionExecutor) Name() string

func (*InstructionExecutor) PermissionVerify

func (t *InstructionExecutor) PermissionVerify(op string, collection string, publickey string) bool

TODO: do not enable permission verification unless you can load all collections at start up

func (*InstructionExecutor) Start

func (t *InstructionExecutor) Start()

func (*InstructionExecutor) Stop

func (t *InstructionExecutor) Stop()

func (*InstructionExecutor) UpdateCollectionFeatures

func (t *InstructionExecutor) UpdateCollectionFeatures(collection string, feature map[string]interface{}) (bool, *CollectionCommand)

更新Coll

type InstructionExecutorConfig

type InstructionExecutorConfig struct {
	BatchSize     int64
	ReadTimeout   time.Duration
	WriteTimeout  time.Duration
	ErrorInterval time.Duration
}

type MasterDataDoc

type MasterDataDoc struct {
	OpHash     string            `json:"op_hash"`
	Collection string            `json:"collection"` //操作的数据表
	Feature    CollectionFeature `json:"feature"`
	PublicKey  string            `json:"public_key"` //公钥
	Signature  string            `json:"signature"`  //签名
	Timestamp  int64             `json:"timestamp"`
}

current data

type MasterDocInfoDoc

type MasterDocInfoDoc struct {
	Collection string `json:"collection"` //操作的数据表
	Version    int    `json:"version"`
	CreatedAt  int64  `json:"created_at"` // timestamp ms
	CreatedBy  string `json:"created_by"`
	ModifiedAt int64  `json:"modified_at"` // timestamp ms
	ModifiedBy string `json:"modified_by"`
}

info table

type MasterHistoryDoc

type MasterHistoryDoc struct {
	OpHash     string            `json:"op_hash"`
	Version    int               `json:"version"`
	TxHash     string            `json:"tx_hash"`
	Collection string            `json:"collection"` //操作的数据表
	Feature    CollectionFeature `json:"feature"`
	PublicKey  string            `json:"public_key"` //公钥
	Signature  string            `json:"signature"`  //签名
	Timestamp  int64             `json:"timestamp"`
}

history data

type MasterOpRecordDoc

type MasterOpRecordDoc struct {
	OpHash     string            `json:"op_hash"`
	TxHash     string            `json:"tx_hash"`
	Collection string            `json:"collection"` //操作的数据表
	Feature    CollectionFeature `json:"feature"`
	PublicKey  string            `json:"public_key"` //公钥
	Signature  string            `json:"signature"`  //签名
	Timestamp  int64             `json:"timestamp"`
}

operation

type OpDoc

type OpDoc struct {
	Order      int32  `json:"oder"`
	IsExecuted bool   `json:"is_executed"`
	TxHash     string `json:"tx_hash"`
	OpHash     string `json:"op_hash"`
	OpStr      string `json:"op_str"`
	Signature  string `json:"signature"`
	PublicKey  string `json:"public_key"`
}

OpDoc is the task queue filled by chain sync. update OpDoc once the OpDoc is executed.

type OpRecordDoc

type OpRecordDoc struct {
	DocId   string `json:"doc_id"`  // 文档Id
	OpHash  string `json:"op_hash"` //数据的hash
	Version int    `json:"version"`
	//Collection string                 `json:"collection"` //操作的数据表
	Operation string                 `json:"operation"`
	Timestamp string                 `json:"timestamp"`
	Data      map[string]interface{} `json:"data"`       //操作记录
	PublicKey string                 `json:"public_key"` //公钥
	Signature string                 `json:"signature"`  //签名
}

oprecord table. One for each collection

func GetOpRecordsById

func GetOpRecordsById(hash string, coll string) []OpRecordDoc

type UpdateCommand

type UpdateCommand struct {
	//OpHash     string                 `json:"op_hash"`
	Op         string                 `json:"op"`
	Collection string                 `json:"collection"` //要操作的数据表
	Query      map[string]string      `json:"query"`
	Set        map[string]interface{} `json:"set"`
	Unset      []string               `json:"unset"`
	PublicKey  string                 `json:"public_key"` //公钥
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL