Documentation
¶
Index ¶
- Constants
- Variables
- func CheckIndexName(name string) error
- func CheckStorageType(storageType string) error
- func CheckTier(tier string) error
- func DeleteIndex(name string) error
- func DeleteTemplate(name string) error
- func ExplainTiering(index *Index, lifecycle *meta.IndexLifecycle, now time.Time) (age time.Duration, action, next string)
- func IncrMetricStatsByIndex(index, field string)
- func ListTemplates(pattern string) ([]*meta.Template, error)
- func LoadTemplate(name string) (*meta.IndexTemplate, bool, error)
- func LoadZedIndexesFromMetadata(version string) error
- func MoveIndexTier(name, tier string) error
- func MultiSearch(indexNames []string, query *meta.ZedQuery) (*meta.SearchResponse, error)
- func NewTemplate(name string, template *meta.IndexTemplate) error
- func OpenIndexReader(name string, storageType string, defaultSearchAnalyzer *analysis.Analyzer, ...) (*riot.Reader, error)
- func OpenIndexWriter(name string, storageType string, defaultSearchAnalyzer *analysis.Analyzer, ...) (*riot.Writer, error)
- func ParseAge(value string) (time.Duration, error)
- func ResolveLifecycle(index *Index) (*meta.IndexLifecycle, error)
- func SetMetricStatsByIndex(index, field string, val float64)
- func StartTiering(ctx context.Context)
- 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) GetIndexType() string
- func (index *Index) GetMappings() *meta.Mappings
- func (index *Index) GetName() string
- func (index *Index) GetReaders(timeMin, timeMax int64) ([]*riot.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) GetTier() string
- func (index *Index) GetWALSize() uint64
- func (index *Index) IsCold() bool
- func (index *Index) IsReadOnly() bool
- func (index *Index) MarshalJSON() ([]byte, error)
- func (index *Index) Reopen() error
- func (index *Index) Search(query *meta.ZedQuery) (*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{}) (*riot.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) ([]*riot.Reader, error)
- func (s *IndexShard) GetShardName() string
- func (s *IndexShard) GetShardNum() int64
- func (s *IndexShard) GetWALSize() (uint64, error)
- func (s *IndexShard) GetWriter(shardID ...int64) (*riot.Writer, error)
- func (s *IndexShard) GetWriters() ([]*riot.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 ( TierHot = "hot" TierWarm = "warm" TierCold = "cold" )
Data tiers. An index is hot on local disk, warm on object storage while still writable by its owner, and cold on object storage read-only, where any node may open it at the same time.
const ( StorageTypeDisk = "disk" StorageTypeS3 = "s3" StorageTypeMinIO = "minio" // alias of s3: MinIO is S3-compatible and shares the [S3] config StorageTypeGCS = "gcs" // Google Cloud Storage, [GCS] config StorageTypeOSS = "oss" // Alibaba Cloud OSS, [OSS] config )
const ( ILMPhaseWarm = "warm" ILMPhaseCold = "cold" ILMPhaseDelete = "delete" )
ILM phase names understood by the lifecycle mover.
const MaxBatchSize = 10240
MaxBatchSize used to limit memory
Variables ¶
var ErrIndexReadOnly = stderrors.New("index is cold (read-only)")
ErrIndexReadOnly is returned by every write path of a cold index.
var Telemetry = newTelemetry()
Telemetry instance
var ZED_METRICS = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Subsystem: "zed", Name: "index_stats", Help: "Summary index stats metric", }, []string{"index", "field"})
ZED_METRICS holds per index stats, exported once prometheus is enabled.
Functions ¶
func CheckIndexName ¶
func CheckStorageType ¶
CheckStorageType validates storage_type and confirms the backend is usable.
func DeleteIndex ¶
func DeleteTemplate ¶
DeleteTemplate delete a template from local
func ExplainTiering ¶
func ExplainTiering(index *Index, lifecycle *meta.IndexLifecycle, now time.Time) (age time.Duration, action, next string)
ExplainTiering reports how old an index is and which lifecycle phase it is heading for: the phase due now, or the next one it will reach.
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 MoveIndexTier ¶
MoveIndexTier moves an index between hot, warm and cold.
Writes are stopped, the WAL is drained and the writers are closed, then every segment of every shard is copied to the new location, the new location is persisted and the index is reopened (read-only when cold). The old copy is dropped only after that succeeded, which makes the move idempotent: running it again after a crash re-copies and finishes the pending steps.
func MultiSearch ¶
func NewTemplate ¶
func NewTemplate(name string, template *meta.IndexTemplate) error
NewTemplate create a template and store in local
func OpenIndexReader ¶
func OpenIndexReader(name string, storageType string, defaultSearchAnalyzer *analysis.Analyzer, timeRange ...int64) (*riot.Reader, error)
OpenIndexReader opens the index read-only, without a writer or WAL, so cold indexes on object storage can be searched from any node at the same time.
func OpenIndexWriter ¶
func OpenIndexWriter(name string, storageType string, defaultSearchAnalyzer *analysis.Analyzer, timeRange ...int64) (*riot.Writer, error)
LoadIndexWriter load the index writer from the storage
func ParseAge ¶
ParseAge parses an ILM duration, adding the "d" (days) unit that time.ParseDuration does not support.
func ResolveLifecycle ¶
func ResolveLifecycle(index *Index) (*meta.IndexLifecycle, error)
ResolveLifecycle returns the lifecycle of an index with the phases of its ILM policy filled in. Values set directly on the index win over the policy.
func SetMetricStatsByIndex ¶
func StartTiering ¶
StartTiering runs the hot/warm/cold lifecycle mover until ctx is done. It is a no-op unless ZED_TIER_ENABLE is set.
func UseTemplate ¶
func UseTemplate(indexName string) (*meta.IndexTemplate, error)
UseTemplate use a specific template for new index
Types ¶
type AliasList ¶
var ZED_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 zed 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 zed index
func (*Index) DeleteDocument ¶
DeleteDocument deletes a document in the zed index
func (*Index) GetAllShardNum ¶
func (*Index) GetDocument ¶
GetDocument get a document in the zed index
func (*Index) GetIndexType ¶
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) IsReadOnly ¶
IsReadOnly reports whether the index rejects writes.
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 zed 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 ZED_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.ZED_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{}) (*riot.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) ([]*riot.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) (*riot.Writer, error)
GetWriter return the newest shard writer or special shard writer
func (*IndexShard) GetWriters ¶
func (s *IndexShard) GetWriters() ([]*riot.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 ZED_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)