Documentation
¶
Index ¶
- Constants
- Variables
- func CheckIndexName(name string) error
- func DeleteIndex(name string) error
- func DeleteTemplate(name string) error
- func IncrMetricStatsByIndex(index, field string)
- func ListTemplates(pattern string) ([]*meta.Template, error)
- func LoadTemplate(name string) (*meta.IndexTemplate, bool, error)
- func LoadZincIndexesFromMetadata(version string) error
- func MultiSearch(indexNames []string, query *meta.ZincQuery) (*meta.SearchResponse, error)
- func NewTemplate(name string, template *meta.IndexTemplate) error
- func OpenIndexWriter(name string, storageType string, defaultSearchAnalyzer *analysis.Analyzer, ...) (*bluge.Writer, error)
- func SetMetricStatsByIndex(index, field string, val float64)
- func StoreIndex(index *Index) error
- func UseTemplate(indexName string) (*meta.IndexTemplate, error)
- type AliasList
- func (al *AliasList) AddIndexesToAlias(alias string, indexes []string) error
- func (al *AliasList) GetAliasMap(targetIndexes, targetAliases []string) M
- func (al *AliasList) GetAliasesForIndex(indexName string) []string
- func (al *AliasList) GetIndexesForAlias(aliasName string) ([]string, bool)
- func (al *AliasList) RemoveIndexesFromAlias(alias string, removeIndexes []string) error
- type Index
- func (index *Index) CheckShards() error
- func (index *Index) Close() error
- func (index *Index) CreateDocument(docID string, doc map[string]interface{}, update bool) error
- func (index *Index) DeleteDocument(docID string) error
- func (index *Index) GetAllShardNum() int64
- func (index *Index) GetAnalyzers() map[string]*analysis.Analyzer
- func (index *Index) GetDocument(docID string) (*meta.Hit, error)
- func (index *Index) GetIndex() meta.Index
- func (index *Index) GetMappings() *meta.Mappings
- func (index *Index) GetName() string
- func (index *Index) GetReaders(timeMin, timeMax int64) ([]*bluge.Reader, error)
- func (index *Index) GetSettings() *meta.IndexSettings
- func (index *Index) GetShardByDocID(docID string) *IndexShard
- func (index *Index) GetShardNum() int64
- func (index *Index) GetStats() meta.IndexStat
- func (index *Index) GetStorageType() string
- func (index *Index) GetWALSize() uint64
- func (index *Index) MarshalJSON() ([]byte, error)
- func (index *Index) Reopen() error
- func (index *Index) Search(query *meta.ZincQuery) (*meta.SearchResponse, error)
- func (index *Index) SetAnalyzers(analyzers map[string]*analysis.Analyzer) error
- func (index *Index) SetMappings(mappings *meta.Mappings) error
- func (index *Index) SetSettings(settings *meta.IndexSettings) error
- func (index *Index) UpdateDocument(docID string, doc map[string]interface{}, insert bool) error
- func (index *Index) UpdateMetadata() error
- func (index *Index) UpdateMetadataByShard(id string)
- func (index *Index) UpdateStatsBySecondShard(id string, secondIndex int64)
- func (index *Index) UpdateWALSize(size uint64)
- func (index *Index) UseTemplate() error
- type IndexList
- func (t *IndexList) Add(index *Index)
- func (t *IndexList) Close() error
- func (t *IndexList) Delete(name string)
- func (t *IndexList) GC() error
- func (t *IndexList) Get(name string) (*Index, bool)
- func (t *IndexList) GetOrCreate(name, storageType string, shardNum int64) (*Index, bool, error)
- func (t *IndexList) Len() int
- func (t *IndexList) List() []*Index
- func (t *IndexList) ListMap() map[string]*Index
- func (t *IndexList) ListName() []string
- func (t *IndexList) ListStat() []*Index
- type IndexSecondShard
- type IndexShard
- func (s *IndexShard) BuildBlugeDocumentFromJSON(docID string, doc map[string]interface{}) (*bluge.Document, error)
- func (s *IndexShard) CheckDocument(docID string, doc map[string]interface{}, update bool, shard int64) ([]byte, error)
- func (s *IndexShard) CheckShards() error
- func (s *IndexShard) Close() error
- func (s *IndexShard) ConsumeWAL() bool
- func (s *IndexShard) FindDocumentByDocID(docID string) (*meta.Hit, error)
- func (s *IndexShard) FindShardByDocID(docID string) (int64, error)
- func (s *IndexShard) GetID() string
- func (s *IndexShard) GetIndexName() string
- func (s *IndexShard) GetLatestShardID() int64
- func (s *IndexShard) GetReaders(timeMin, timeMax int64) ([]*bluge.Reader, error)
- func (s *IndexShard) GetShardName() string
- func (s *IndexShard) GetShardNum() int64
- func (s *IndexShard) GetWALSize() (uint64, error)
- func (s *IndexShard) GetWriter(shardID ...int64) (*bluge.Writer, error)
- func (s *IndexShard) GetWriters() ([]*bluge.Writer, error)
- func (s *IndexShard) NewShard() error
- func (s *IndexShard) OpenWAL() error
- func (s *IndexShard) Rollback() error
- func (s *IndexShard) SetTimestamp(t int64)
- type IndexShardWALList
- type M
Constants ¶
const ( ShardIDNeedLatest int64 = -1 // get lastest shardID ShardIDNeedUpdate int64 = -2 // get all shardIDs )
const ( RedoActionRead = uint64(1) RedoActionWrite = uint64(2) RedoActionTruncate = uint64(3) )
const MaxBatchSize = 10240
MaxBatchSize used to limit memory
Variables ¶
var Telemetry = newTelemetry()
Telemetry instance
var ZINC_METRICS *ginprometheus.Metric
Functions ¶
func CheckIndexName ¶
func DeleteIndex ¶
func DeleteTemplate ¶
DeleteTemplate delete a template from local
func IncrMetricStatsByIndex ¶
func IncrMetricStatsByIndex(index, field string)
func ListTemplates ¶
ListTemplates returns all templates
func LoadTemplate ¶
func LoadTemplate(name string) (*meta.IndexTemplate, bool, error)
LoadTemplate load a specific template from local
func MultiSearch ¶
func NewTemplate ¶
func NewTemplate(name string, template *meta.IndexTemplate) error
NewTemplate create a template and store in local
func OpenIndexWriter ¶
func OpenIndexWriter(name string, storageType string, defaultSearchAnalyzer *analysis.Analyzer, timeRange ...int64) (*bluge.Writer, error)
LoadIndexWriter load the index writer from the storage
func SetMetricStatsByIndex ¶
func UseTemplate ¶
func UseTemplate(indexName string) (*meta.IndexTemplate, error)
UseTemplate use a specific template for new index
Types ¶
type AliasList ¶
var ZINC_INDEX_ALIAS_LIST AliasList
func NewAliasList ¶
func NewAliasList() *AliasList
func (*AliasList) AddIndexesToAlias ¶
func (*AliasList) GetAliasMap ¶
GetAliasMap returns an ES compatible map of indexes to their aliases In the form:
{"gitea_issues":{"aliases":{}},"gitea_codes.v1":{"aliases":{"gitea_codes":{}}}}
func (*AliasList) GetAliasesForIndex ¶
func (*AliasList) GetIndexesForAlias ¶
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
func GetOrCreateIndex ¶
func NewIndex ¶
NewIndex creates an instance of a physical zinc index that can be used to store and retrieve data.
func (*Index) CheckShards ¶
CheckShards check all shards status if need create new second layer shard
func (*Index) CreateDocument ¶
CreateDocument inserts or updates a document in the zinc index
func (*Index) DeleteDocument ¶
DeleteDocument deletes a document in the zinc index
func (*Index) GetAllShardNum ¶
func (*Index) GetDocument ¶
GetDocument get a document in the zinc index
func (*Index) GetMappings ¶
func (*Index) GetReaders ¶
GetReaders return all shard readers
func (*Index) GetSettings ¶
func (index *Index) GetSettings() *meta.IndexSettings
func (*Index) GetShardByDocID ¶
func (index *Index) GetShardByDocID(docID string) *IndexShard
GetShardByDocID return the shard by hash docID
func (*Index) GetShardNum ¶
func (*Index) GetStorageType ¶
func (*Index) GetWALSize ¶
func (*Index) MarshalJSON ¶
func (*Index) Reopen ¶
Reopen just close the index, it will open automatically by trigger Deprecated: it will be removed in the future
func (*Index) SetAnalyzers ¶
func (*Index) SetSettings ¶
func (index *Index) SetSettings(settings *meta.IndexSettings) error
func (*Index) UpdateDocument ¶
UpdateDocument updates a document in the zinc index
func (*Index) UpdateMetadata ¶
UpdateMetadata update index metadata, mainly docNum and storageSize need merge from all first layer shards
func (*Index) UpdateMetadataByShard ¶
UpdateMetadataByShard update first layer shard metadata, mainly docNum, storageSize and timeRange need merge from all second layer shards
func (*Index) UpdateStatsBySecondShard ¶
UpdateStatsBySecondShard update second layer shard stats, mainly docNum and storageSize
func (*Index) UpdateWALSize ¶
func (*Index) UseTemplate ¶
type IndexList ¶
var ZINC_INDEX_LIST IndexList
func (*IndexList) GetOrCreate ¶
type IndexSecondShard ¶
type IndexSecondShard struct {
// contains filtered or unexported fields
}
IndexSecondShard second layer shard by auto increate shards for index. Under first layer shards, Documents will store in this layer shards. Use a environment `config.ZINC_SHARD_MAX_SIZE` to control second layer shard max size. If the shard size over limit then will auto create a new shard for accept new documents. And we will log time range for this layer shards, when query data we can use time range filter which shards need to find data. We keep one shard size wouldn't over limit, we will fozen old shards, just write new documents to new shards and do merge in new shards this will improve shard performance.
type IndexShard ¶
type IndexShard struct {
// contains filtered or unexported fields
}
IndexShard first layer shard by fixed number shards for index. Use hash algorithm distribute documents to different shards. This shards let we can concurrency write to many shards in same index. The shards num can not be modify, because if change the num hash algorithm will distribute the same docID to another shard, then we will can not found the old document, maybe cause duplicate documents. First layer shard just used for distribute not really store documents.
func (*IndexShard) BuildBlugeDocumentFromJSON ¶
func (s *IndexShard) BuildBlugeDocumentFromJSON(docID string, doc map[string]interface{}) (*bluge.Document, error)
BuildBlugeDocumentFromJSON returns the bluge document for the json document. It also updates the mapping for the fields if not found. If no mappings are found, it creates te mapping for all the encountered fields. If mapping for some fields is found but not for others then it creates the mapping for the missing fields.
func (*IndexShard) CheckDocument ¶
func (s *IndexShard) CheckDocument(docID string, doc map[string]interface{}, update bool, shard int64) ([]byte, error)
CheckDocument checks if the document is valid.
func (*IndexShard) CheckShards ¶
func (s *IndexShard) CheckShards() error
CheckShards check current shard is reach the maximum shard size or create a new shard
func (*IndexShard) Close ¶
func (s *IndexShard) Close() error
func (*IndexShard) ConsumeWAL ¶
func (s *IndexShard) ConsumeWAL() bool
ConsumeWAL consume WAL for index returns if there is any data updated
func (*IndexShard) FindDocumentByDocID ¶
func (s *IndexShard) FindDocumentByDocID(docID string) (*meta.Hit, error)
FindDocumentByDocID finds docID and returns the document
func (*IndexShard) FindShardByDocID ¶
func (s *IndexShard) FindShardByDocID(docID string) (int64, error)
FindShardByDocID finds docID in which shard and returns the shard id
func (*IndexShard) GetID ¶
func (s *IndexShard) GetID() string
func (*IndexShard) GetIndexName ¶
func (s *IndexShard) GetIndexName() string
func (*IndexShard) GetLatestShardID ¶
func (s *IndexShard) GetLatestShardID() int64
func (*IndexShard) GetReaders ¶
func (s *IndexShard) GetReaders(timeMin, timeMax int64) ([]*bluge.Reader, error)
GetReaders return all shard readers
func (*IndexShard) GetShardName ¶
func (s *IndexShard) GetShardName() string
func (*IndexShard) GetShardNum ¶
func (s *IndexShard) GetShardNum() int64
func (*IndexShard) GetWALSize ¶
func (s *IndexShard) GetWALSize() (uint64, error)
func (*IndexShard) GetWriter ¶
func (s *IndexShard) GetWriter(shardID ...int64) (*bluge.Writer, error)
GetWriter return the newest shard writer or special shard writer
func (*IndexShard) GetWriters ¶
func (s *IndexShard) GetWriters() ([]*bluge.Writer, error)
GetWriters return all shard writers
func (*IndexShard) NewShard ¶
func (s *IndexShard) NewShard() error
func (*IndexShard) Rollback ¶
func (s *IndexShard) Rollback() error
func (*IndexShard) SetTimestamp ¶
func (s *IndexShard) SetTimestamp(t int64)
type IndexShardWALList ¶
type IndexShardWALList struct { Shards map[string]*IndexShard // contains filtered or unexported fields }
var ZINC_INDEX_SHARD_WAL_LIST IndexShardWALList
Record opened WAL used to do consume
func (*IndexShardWALList) Add ¶
func (t *IndexShardWALList) Add(shard *IndexShard)
func (*IndexShardWALList) ConsumeWAL ¶
func (t *IndexShardWALList) ConsumeWAL()
func (*IndexShardWALList) Len ¶
func (t *IndexShardWALList) Len() int
func (*IndexShardWALList) List ¶
func (t *IndexShardWALList) List() []*IndexShard
func (*IndexShardWALList) Remove ¶
func (t *IndexShardWALList) Remove(name string)