Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyReplicaEntries(index *Index, shardID string, entries [][]byte) error
- func CheckIndexName(name string) error
- func CheckStorageType(storageType string) error
- func CheckTier(tier string) error
- func DeleteIndex(name string) error
- func DeleteSynonymSet(id string) ([]string, error)
- func DeleteTemplate(name string) error
- func DropLocalIndex(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 InstallSnapshot(name string, indexMeta []byte, dir string) error
- func ListTemplates(pattern string) ([]*meta.Template, error)
- func LoadTemplate(name string) (*meta.IndexTemplate, bool, error)
- func LoadZedIndexesFromMetadata(version string) error
- func LookupSynonymSet(id string) ([]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 GetIndex(name string) (*Index, bool)
- func GetOrCreateIndex(name, storageType string, shardNum int64) (*Index, bool, error)
- func GetOrCreateIndexWith(name, storageType string, shardNum int64, init func(*Index) error) (*Index, bool, error)
- func LoadIndex(name string) (*Index, error)
- func NewIndex(name, storageType string, shardNum int64) (*Index, error)
- 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) ExcludeSourceVectors() bool
- func (index *Index) Flush() 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) IsDisk() bool
- func (index *Index) IsReadOnly() bool
- func (index *Index) MarshalJSON() ([]byte, error)
- func (index *Index) Refresh() 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) SnapshotTo(dir string) ([]byte, error)
- func (index *Index) SyncWAL() 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
- func (index *Index) WaitApplied(timeout time.Duration) 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, init func(*Index) error) (*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
- type StorageError
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 ( // WALHook sees every entry a local write appends to a shard WAL, in WAL // order per shard. Entries applied through ApplyReplicaEntries skip it. WALHook func(index, shard string, entry []byte) // StoreGuard returning false keeps storeIndex from writing the shared // index metadata: a replica must not overwrite the owner's record. StoreGuard func(index string) bool // WriteGuard returning an error rejects a local write before it reaches // the WAL: a copy of an index another node owns must not diverge. WriteGuard func(index string) error )
Hooks the cluster replication layer installs. Both are nil in a single node build. They are set once at startup, before any request is served.
var ErrIndexReadOnly = stderrors.New("index is cold (read-only)")
ErrIndexReadOnly is returned by every write path of a cold index.
var RiotCollector prometheus.Collector = riotCollector{}
RiotCollector exports the stats of every open riot writer at scrape time.
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 ApplyReplicaEntries ¶
ApplyReplicaEntries appends WAL entries recorded on the owner to the WAL of the same shard here. Every entry is rewritten to an update across all second layer shards, which makes it idempotent: the replica's second layer layout may differ from the owner's, and an entry may be applied twice when a snapshot already contains it.
func CheckIndexName ¶
func CheckStorageType ¶
CheckStorageType validates storage_type and confirms the backend is usable.
func DeleteIndex ¶
func DeleteSynonymSet ¶ added in v1.4.0
DeleteSynonymSet deletes the synonyms set id unless an index references it, returning the sorted names of those indexes instead.
func DeleteTemplate ¶
DeleteTemplate delete a template from local
func DropLocalIndex ¶
DropLocalIndex closes an index and removes its local files, leaving the shared metadata and any bucket untouched: the copy a replica keeps of an index its owner deleted.
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 InstallSnapshot ¶
InstallSnapshot replaces the local copy of an index with a snapshot made by SnapshotTo: the open index is closed, its directory (WAL included) is replaced by dir and the index is rebuilt from the snapshot metadata. dir must be on the same file system as the data path.
func ListTemplates ¶
ListTemplates returns all templates
func LoadTemplate ¶
func LoadTemplate(name string) (*meta.IndexTemplate, bool, error)
LoadTemplate load a specific template from local
func LookupSynonymSet ¶ added in v1.4.0
LookupSynonymSet returns the rules of the stored synonyms set id.
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 GetOrCreateIndexWith ¶ added in v1.3.0
func GetOrCreateIndexWith(name, storageType string, shardNum int64, init func(*Index) error) (*Index, bool, error)
GetOrCreateIndexWith is GetOrCreateIndex running init on a new index before it is stored and cached, so no one sees it half set up. init runs under the index list lock and must not call GetIndex or GetOrCreateIndex.
func LoadIndex ¶
LoadIndex returns the index, loading it from the metadata store when this node has not seen it yet (it was created on another node).
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) ExcludeSourceVectors ¶ added in v1.3.0
ExcludeSourceVectors reports whether new documents keep their vector fields out of the stored _source.
func (*Index) Flush ¶
Flush blocks writes, applies the WAL and closes the writers, which persists every segment. Writers and WAL reopen on the next request.
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) Refresh ¶ added in v1.3.0
Refresh waits until the documents written so far are searchable. The WAL consumer applies them, so writers and WAL stay open. After a restart a shard WAL stays closed until its first write and may still hold entries, so every shard WAL of a writable index is opened first, handing them to the consumer.
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) SnapshotTo ¶
SnapshotTo copies a point in time view of every second layer shard of a disk index into dir, laid out like the data path, after the WAL written so far was applied. It returns the index metadata of that view.
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) OpenWAL ¶
func (s *IndexShard) OpenWAL() error
OpenWAL publishes the shard to writers and the consumer only after recovery.
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)
Remove waits for any consumer pass using the shard, including its metadata update.
type StorageError ¶ added in v1.3.0
type StorageError struct{ Err error }
StorageError marks a write that failed in the WAL or metadata store rather than because of the document, so the client may retry it.
func (*StorageError) Error ¶ added in v1.3.0
func (e *StorageError) Error() string
func (*StorageError) Unwrap ¶ added in v1.3.0
func (e *StorageError) Unwrap() error
Source Files
¶
- aliaslist.go
- deleteindex.go
- index.go
- index_document.go
- index_shards.go
- index_shards_document.go
- index_shards_wal.go
- index_shards_wallist.go
- index_tier.go
- indexlist.go
- loadindexes.go
- metrics.go
- metrics_riot.go
- multi_search.go
- newindex.go
- replication.go
- search.go
- search_ext.go
- synonyms.go
- telemetry.go
- template.go
- tiering.go