db

package
v0.0.0-...-7662171 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INDEX_OWNER = "IX_OWNER"
	IAdd        = "I_ADD"
	SAdd        = "S_ADD"
)
View Source
const (
	IndexObjectType = "INDEX"
)

Variables

View Source
var Errors map[int]string = map[int]string{
	10400000: "IRecord.ToJson: fail marshal",
	10400001: "SRecord.ToJson: fail marshal",
	10400002: "IItem.ToJson: fail marshal",
	10400003: "SItem.ToJson: fail marshal",

	10401000: "SimpleIndex.IAdd: read lock fail wait",
	10401001: "SimpleIndex.IAdd: Permission denied",

	10401050: "SimpleIndex.SAdd: read lock fail wait",
	10401051: "SimpleIndex.SAdd: Permission denied",

	10401002: "SimpleIndex.IAdd: Check records segments fail i: %v, s:%v",
	10401052: "SimpleIndex.SAdd: Check records segments fail i: %v, s:%v",
	10401003: "SimpleIndex.IAdd: No valid data",
	10401053: "SimpleIndex.SAdd: No valid data",
	10401004: "SimpleIndex.IAdd: Promote for add segment",
	10401054: "SimpleIndex.SAdd: Promote for add segment",

	10401100: "ISimpleIndexBlock.Add: Lock fail wait",
	10401150: "SSimpleIndexBlock.Add: Lock fail wait",
	10401101: "ISimpleIndexBlockSegment.Add: Impossible situation index of start more then end block",
	10401151: "SSimpleIndexBlockSegment.Add: Impossible situation index of start more then end block",
	10401102: "ISimpleIndexBlockSegment.Add: RLock fail wait",
	10401152: "SSimpleIndexBlockSegment.Add: RLock fail wait",
	10401103: "ISimpleIndexBlockSegment.Add: Promote for add first element fail wait",
	10401153: "SSimpleIndexBlockSegment.Add: Promote for add first element fail wait",
	10401104: "ISimpleIndexBlockSegment.Add: Promote for split by count fail wait",
	10401154: "SSimpleIndexBlockSegment.Add: Promote for split by count fail wait",
	10401105: "ISimpleIndexBlockSegment.Add: Impossible situation index of start more then end block (locks)",
	10401155: "SSimpleIndexBlockSegment.Add: Impossible situation index of start more then end block (locks)",
}

Errors codes and description

Functions

func GenerateError

func GenerateError(key int, a ...interface{}) *mft.Error

GenerateError -

func GenerateErrorE

func GenerateErrorE(key int, err error, a ...interface{}) *mft.Error

GenerateErrorE -

func GenerateErrorForCapUser

func GenerateErrorForCapUser(user cn.CapUser, key int, a ...interface{}) *mft.Error

GenerateError -

func GenerateErrorForCapUserE

func GenerateErrorForCapUserE(user cn.CapUser, key int, err error, a ...interface{}) *mft.Error

GenerateError -

Types

type GetIndexRequest

type GetIndexRequest struct {
	// Segment - segment for search; if NoSegment == true segments is not used
	Segment int64 `json:"segment,omitempty"`
	// NoSegment if true segments is not used
	NoSegment bool `json:"no_segment,omitempty"`

	// GetList if set then Key => FromKey and used ToKey
	GetList bool `json:"get_list,omitempty"`
}

type GetIndexResponce

type GetIndexResponce struct {
	IRecords []IIndexRecord `json:"ir,omitempty"`
	SRecords []SIndexRecord `json:"sr,omitempty"`
}

type GetItemRequest

type GetItemRequest struct {
	// Segment - segment for search; if NoSegment == true segments is not used
	Segment int64 `json:"segment,omitempty"`
	// NoSegment if true segments is not used
	NoSegment bool `json:"no_segment,omitempty"`

	// GetList if set then Key => FromKey and used ToKey
	GetList bool `json:"get_list,omitempty"`
}

type IAddIndexRequest

type IAddIndexRequest struct {
	Key      int64         `json:"key"`
	IRecord  *IIndexRecord `json:"ir,omitempty"`
	SRecord  *SIndexRecord `json:"sr,omitempty"`
	SaveMode cn.SaveMode   `json:"save_mode,omitempty"`
}

type IAddStorageRequest

type IAddStorageRequest struct {
	Key    int64   `json:"key"`
	Record IRecord `json:"ir,omitempty"`
	// ConflictInit if true and exists conflict record then conflict will be begin
	// ConflictInit if false and exists conflict record then error
	ConflictInit bool        `json:"conflict_init,omitempty"`
	SaveMode     cn.SaveMode `json:"save_mode,omitempty"`
}

type IGetIndexRequest

type IGetIndexRequest struct {
	Key int64 `json:"key"`
	GetIndexRequest
	// ToKey - get values from Key - to ToKey; requare GetList flag
	ToKey int64 `json:"to_key,omitempty"`
}

type IGetItemRequest

type IGetItemRequest struct {
	Key int64 `json:"key"`
	GetItemRequest
	// ToKey - get values from Key - to ToKey; requare GetList flag
	ToKey int64 `json:"to_key,omitempty"`
}

type IIndexRecord

type IIndexRecord struct {
	ID      int64 `json:"id"`
	Version int64 `json:"version"`
	Segment int64 `json:"segment,omitempty"`
}

func IRecordsAdd

func IRecordsAdd(records []IIndexRecord, record *IIndexRecord) (res []IIndexRecord, do bool)

type IItem

type IItem struct {
	ID int64 `json:"id"`

	// Current version
	Version int64 `json:"version"`
	// Records actual records Version is key
	Records map[int64]*IRecord `json:"records"`

	ConflictVersions []int64 `json:"conflict,omitempty"`
}

func (*IItem) ToJson

func (r *IItem) ToJson() json.RawMessage

type IRecord

type IRecord struct {
	ID int64 `json:"id"`
	Record
}

func (*IRecord) ToJson

func (r *IRecord) ToJson() json.RawMessage

type ISimpleIndexBlock

type ISimpleIndexBlock struct {
	ID int64 `json:"block_id"`

	KeyStart int64 `json:"key_start"`
	KeyEnd   int64 `json:"key_end"`

	CountKeys  int `json:"count_keys"`
	CountItems int `json:"count_items"`

	Keys []*ISimpleIndexKeyStorage `json:"-"`

	LastSavedVersion int64 `json:"last_saved_version"`
	LastVersion      int64 `json:"-"`
	// contains filtered or unexported fields
}

func (*ISimpleIndexBlock) Add

func (*ISimpleIndexBlock) SplitHalf

func (ib *ISimpleIndexBlock) SplitHalf(si *SimpleIndex) (ib1 *ISimpleIndexBlock, ib2 *ISimpleIndexBlock)

type ISimpleIndexBlockSegment

type ISimpleIndexBlockSegment struct {
	Segment int64                `json:"segments"`
	Blocks  []*ISimpleIndexBlock `json:"-"`

	LastSavedVersion int64 `json:"last_saved_version"`
	LastVersion      int64 `json:"-"`
	// contains filtered or unexported fields
}

func (*ISimpleIndexBlockSegment) Add

type ISimpleIndexKeyStorage

type ISimpleIndexKeyStorage struct {
	Key      int64          `json:"key"`
	IRecords []IIndexRecord `json:"ir"`
	SRecords []SIndexRecord `json:"sr"`
}

func (*ISimpleIndexKeyStorage) Add

type Index

type Index interface {
	Name(ctx context.Context, user cn.CapUser) (name string, err *mft.Error)
	NameSet(ctx context.Context, user cn.CapUser, name string) (err *mft.Error)

	IAdd(ctx context.Context, user cn.CapUser, req IAddIndexRequest) (err *mft.Error)
	SAdd(ctx context.Context, user cn.CapUser, req SAddIndexRequest) (err *mft.Error)

	IAddList(ctx context.Context, user cn.CapUser, req []IAddIndexRequest) (err *mft.Error)
	SAddList(ctx context.Context, user cn.CapUser, req []SAddIndexRequest) (err *mft.Error)

	IGet(ctx context.Context, user cn.CapUser, req IGetIndexRequest) (res map[int64]GetIndexResponce, err *mft.Error)
	SGet(ctx context.Context, user cn.CapUser, req SGetIndexRequest) (res map[string]GetIndexResponce, err *mft.Error)

	IDelete(ctx context.Context, user cn.CapUser, req IAddIndexRequest) (err *mft.Error)
	SDelete(ctx context.Context, user cn.CapUser, req SAddIndexRequest) (err *mft.Error)

	IDeleteList(ctx context.Context, user cn.CapUser, req []IAddIndexRequest) (err *mft.Error)
	SDeleteList(ctx context.Context, user cn.CapUser, req []SAddIndexRequest) (err *mft.Error)

	OptimizeAll(ctx context.Context, user cn.CapUser, deph int) (err *mft.Error)
	Optimize(ctx context.Context, user cn.CapUser, req OptimizeIndexRequest) (err *mft.Error)
}

type OptimizeIndexRequest

type OptimizeIndexRequest struct {
	Segment int64 `json:"segment,omitempty"`
	Deph    int   `json:"deph,omitempty"`
}

type OptimizeStorageRequest

type OptimizeStorageRequest struct {
	Segment int64 `json:"segment,omitempty"`
	Deph    int   `json:"deph,omitempty"`
}

type Record

type Record struct {
	Version   int64               `json:"version"`
	Segment   int64               `json:"segment,omitempty"`
	Data      json.RawMessage     `json:"data"`
	IIndex    map[string][]int64  `json:"iindex,omitempty"`
	SIndex    map[string][]string `json:"sindex,omitempty"`
	IsDeleted bool                `json:"is_deleted,omitempty"`
	// OverVersions - Previous versions, this item is child of this versions
	OverVersions []int64   `json:"over_version,omitempty"`
	Date         time.Time `json:"date"`
}

type ReindexTask

type ReindexTask struct {
	Start      *time.Time `json:"start"`
	End        *time.Time `json:"end"`
	StartedNow bool       `json:"started_now"`
}

type SAddIndexRequest

type SAddIndexRequest struct {
	Key      string        `json:"key"`
	IRecord  *IIndexRecord `json:"ir,omitempty"`
	SRecord  *SIndexRecord `json:"sr,omitempty"`
	SaveMode cn.SaveMode   `json:"save_mode,omitempty"`
}

type SAddStorageRequest

type SAddStorageRequest struct {
	Key    int64   `json:"key"`
	Record SRecord `json:"ir,omitempty"`
	// ConflictInit if true and exists conflict record then conflict will be begin
	// ConflictInit if false and exists conflict record then error
	ConflictInit bool        `json:"conflict_init,omitempty"`
	SaveMode     cn.SaveMode `json:"save_mode,omitempty"`
}

type SGetIndexRequest

type SGetIndexRequest struct {
	Key string `json:"key"`
	GetIndexRequest
	// ToKey - get values from Key - to ToKey; requare GetList flag
	ToKey string `json:"to_key,omitempty"`
}

type SGetItemRequest

type SGetItemRequest struct {
	Key string `json:"key"`
	GetItemRequest
	// ToKey - get values from Key - to ToKey; requare GetList flag
	ToKey string `json:"to_key,omitempty"`
}

type SIndexRecord

type SIndexRecord struct {
	ID      string `json:"id"`
	Version int64  `json:"version"`
	Segment int64  `json:"segment,omitempty"`
}

func SRecordsAdd

func SRecordsAdd(records []SIndexRecord, record *SIndexRecord) (res []SIndexRecord, do bool)

type SItem

type SItem struct {
	ID int64 `json:"id"`

	// Current version
	Version int64 `json:"version"`
	// Records actual records Version is key
	Records map[int64]*SRecord `json:"records"`

	ConflictVersions []int64 `json:"conflict,omitempty"`
}

func (*SItem) ToJson

func (r *SItem) ToJson() json.RawMessage

type SRecord

type SRecord struct {
	ID string `json:"id"`
	Record
}

func (*SRecord) ToJson

func (r *SRecord) ToJson() json.RawMessage

type SSimpleIndexBlock

type SSimpleIndexBlock struct {
	ID int64 `json:"block_id"`

	KeyStart string `json:"key_start"`
	KeyEnd   string `json:"key_end"`

	CountKeys  int `json:"count_keys"`
	CountItems int `json:"count_items"`

	Keys []*SSimpleIndexKeyStorage `json:"-"`

	LastSavedVersion int64 `json:"last_saved_version"`
	LastVersion      int64 `json:"-"`
	// contains filtered or unexported fields
}

func (*SSimpleIndexBlock) Add

func (*SSimpleIndexBlock) SplitHalf

func (ib *SSimpleIndexBlock) SplitHalf(si *SimpleIndex) (ib1 *SSimpleIndexBlock, ib2 *SSimpleIndexBlock)

type SSimpleIndexBlockSegment

type SSimpleIndexBlockSegment struct {
	Segment int64                `json:"segments"`
	Blocks  []*SSimpleIndexBlock `json:"-"`

	LastSavedVersion int64 `json:"last_saved_version"`
	LastVersion      int64 `json:"-"`
	// contains filtered or unexported fields
}

func (*SSimpleIndexBlockSegment) Add

type SSimpleIndexKeyStorage

type SSimpleIndexKeyStorage struct {
	Key      string         `json:"key"`
	IRecords []IIndexRecord `json:"ir"`
	SRecords []SIndexRecord `json:"sr"`
}

func (*SSimpleIndexKeyStorage) Add

type SimpleIndex

type SimpleIndex struct {
	Name      string                      `json:"name"`
	ISegments []*ISimpleIndexBlockSegment `json:"isegments"`
	SSegments []*SSimpleIndexBlockSegment `json:"ssegments"`

	// case nil then ignore
	CheckPermissionFunc func(user cn.CapUser, objectType string, action string, objectName string) (allowed bool, err *mft.Error) `json:"-"`
	// case nil then ignore
	ThrowErrorFunc func(err *mft.Error) bool `json:"-"`

	IdGenerator *mft.G `json:"-"`

	MaxItemsCountInBlock int `json:"max_itm_cnt_in_block"`
	MaxKeysCountInBlock  int `json:"max_key_cnt_in_block"`

	LastSavedVersion int64 `json:"last_saved_version"`
	LastVersion      int64 `json:"-"`
	// contains filtered or unexported fields
}

func (*SimpleIndex) CheckOneOfPermission

func (si *SimpleIndex) CheckOneOfPermission(user cn.CapUser, objectType string, objectName string, actions ...string) (allowed bool, err *mft.Error)

func (*SimpleIndex) CheckPermission

func (si *SimpleIndex) CheckPermission(user cn.CapUser, objectType string, action string, objectName string) (allowed bool, err *mft.Error)

func (*SimpleIndex) IAdd

func (si *SimpleIndex) IAdd(ctx context.Context, user cn.CapUser, req IAddIndexRequest) (err *mft.Error)

func (*SimpleIndex) SAdd

func (si *SimpleIndex) SAdd(ctx context.Context, user cn.CapUser, req SAddIndexRequest) (err *mft.Error)

func (*SimpleIndex) Save

func (si *SimpleIndex) Save(ctx context.Context, user cn.CapUser) (err *mft.Error)

func (*SimpleIndex) ThrowError

func (si *SimpleIndex) ThrowError(err *mft.Error) bool

type Storage

type Storage interface {
	ISet(ctx context.Context, user cn.CapUser, req IAddStorageRequest) (err *mft.Error)
	SSet(ctx context.Context, user cn.CapUser, req SAddStorageRequest) (err *mft.Error)

	ISetList(ctx context.Context, user cn.CapUser, req []IAddStorageRequest) (err *mft.Error)
	SSetList(ctx context.Context, user cn.CapUser, req []SAddStorageRequest) (err *mft.Error)

	IGet(ctx context.Context, user cn.CapUser, req IGetItemRequest) (res map[int64]*IItem, err *mft.Error)
	SGet(ctx context.Context, user cn.CapUser, req SGetItemRequest) (res map[string]*SItem, err *mft.Error)

	// ReIndexItems - reindex current items: add index by last version and remove by previous
	ReIndexItems(ctx context.Context, user cn.CapUser, req []IGetItemRequest) (err *mft.Error)
	// ReIndexAllTaskDo starts reindex if starts by this command then StartedNow = true
	ReIndexAllTaskDo(ctx context.Context, user cn.CapUser) (resp ReindexTask, err *mft.Error)
	ReIndexAllTaskGet(ctx context.Context, user cn.CapUser) (resp ReindexTask, err *mft.Error)

	OptimizeAll(ctx context.Context, user cn.CapUser, deph int) (err *mft.Error)
	Optimize(ctx context.Context, user cn.CapUser, req OptimizeStorageRequest) (err *mft.Error)
}

Jump to

Keyboard shortcuts

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