core

package
v1.0.0-beta7 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 47 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ShardIDNeedLatest int64 = -1 // get lastest shardID
	ShardIDNeedUpdate int64 = -2 // get all shardIDs
)
View Source
const (
	RedoActionRead     = uint64(1)
	RedoActionWrite    = uint64(2)
	RedoActionTruncate = uint64(3)
)
View Source
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.

View Source
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
)
View Source
const (
	ILMPhaseWarm   = "warm"
	ILMPhaseCold   = "cold"
	ILMPhaseDelete = "delete"
)

ILM phase names understood by the lifecycle mover.

View Source
const MaxBatchSize = 10240

MaxBatchSize used to limit memory

Variables

View Source
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.

View Source
var ErrIndexReadOnly = stderrors.New("index is cold (read-only)")

ErrIndexReadOnly is returned by every write path of a cold index.

View Source
var Telemetry = newTelemetry()

Telemetry instance

View Source
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

func ApplyReplicaEntries(index *Index, shardID string, entries [][]byte) error

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 CheckIndexName(name string) error

func CheckStorageType

func CheckStorageType(storageType string) error

CheckStorageType validates storage_type and confirms the backend is usable.

func CheckTier

func CheckTier(tier string) error

CheckTier validates a tier name.

func DeleteIndex

func DeleteIndex(name string) error

func DeleteTemplate

func DeleteTemplate(name string) error

DeleteTemplate delete a template from local

func DropLocalIndex

func DropLocalIndex(name string) error

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

func InstallSnapshot(name string, indexMeta []byte, dir string) error

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

func ListTemplates(pattern string) ([]*meta.Template, error)

ListTemplates returns all templates

func LoadTemplate

func LoadTemplate(name string) (*meta.IndexTemplate, bool, error)

LoadTemplate load a specific template from local

func LoadZedIndexesFromMetadata

func LoadZedIndexesFromMetadata(version string) error

func MoveIndexTier

func MoveIndexTier(name, tier string) error

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 MultiSearch(indexNames []string, query *meta.ZedQuery) (*meta.SearchResponse, error)

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

func ParseAge(value string) (time.Duration, error)

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 SetMetricStatsByIndex(index, field string, val float64)

func StartTiering

func StartTiering(ctx context.Context)

StartTiering runs the hot/warm/cold lifecycle mover until ctx is done. It is a no-op unless ZED_TIER_ENABLE is set.

func StoreIndex

func StoreIndex(index *Index) error

storeIndex stores the index to metadata

func UseTemplate

func UseTemplate(indexName string) (*meta.IndexTemplate, error)

UseTemplate use a specific template for new index

Types

type AliasList

type AliasList struct {
	Aliases map[string][]string
	// contains filtered or unexported fields
}
var ZED_INDEX_ALIAS_LIST AliasList

func NewAliasList

func NewAliasList() *AliasList

func (*AliasList) AddIndexesToAlias

func (al *AliasList) AddIndexesToAlias(alias string, indexes []string) error

func (*AliasList) GetAliasMap

func (al *AliasList) GetAliasMap(targetIndexes, targetAliases []string) M

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 (al *AliasList) GetAliasesForIndex(indexName string) []string

func (*AliasList) GetIndexesForAlias

func (al *AliasList) GetIndexesForAlias(aliasName string) ([]string, bool)

func (*AliasList) RemoveIndexesFromAlias

func (al *AliasList) RemoveIndexesFromAlias(alias string, removeIndexes []string) error

type Index

type Index struct {
	// contains filtered or unexported fields
}

func GetIndex

func GetIndex(name string) (*Index, bool)

func GetOrCreateIndex

func GetOrCreateIndex(name, storageType string, shardNum int64) (*Index, bool, error)

func LoadIndex

func LoadIndex(name string) (*Index, error)

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

func NewIndex(name, storageType string, shardNum int64) (*Index, error)

NewIndex creates an instance of a physical zed index that can be used to store and retrieve data.

func (*Index) CheckShards

func (index *Index) CheckShards() error

CheckShards check all shards status if need create new second layer shard

func (*Index) Close

func (index *Index) Close() error

func (*Index) CreateDocument

func (index *Index) CreateDocument(docID string, doc map[string]interface{}, update bool) error

CreateDocument inserts or updates a document in the zed index

func (*Index) DeleteDocument

func (index *Index) DeleteDocument(docID string) error

DeleteDocument deletes a document in the zed index

func (*Index) Flush

func (index *Index) Flush() error

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 *Index) GetAllShardNum() int64

func (*Index) GetAnalyzers

func (index *Index) GetAnalyzers() map[string]*analysis.Analyzer

func (*Index) GetDocument

func (index *Index) GetDocument(docID string) (*meta.Hit, error)

GetDocument get a document in the zed index

func (*Index) GetIndex

func (index *Index) GetIndex() meta.Index

func (*Index) GetIndexType

func (index *Index) GetIndexType() string

func (*Index) GetMappings

func (index *Index) GetMappings() *meta.Mappings

func (*Index) GetName

func (index *Index) GetName() string

func (*Index) GetReaders

func (index *Index) GetReaders(timeMin, timeMax int64) ([]*riot.Reader, error)

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 *Index) GetShardNum() int64

func (*Index) GetStats

func (index *Index) GetStats() meta.IndexStat

func (*Index) GetStorageType

func (index *Index) GetStorageType() string

func (*Index) GetTier

func (index *Index) GetTier() string

GetTier returns the tier of the index; an index without one is hot.

func (*Index) GetWALSize

func (index *Index) GetWALSize() uint64

func (*Index) IsCold

func (index *Index) IsCold() bool

IsCold reports whether the index is stored read-only on object storage.

func (*Index) IsDisk

func (index *Index) IsDisk() bool

IsDisk reports whether the index data lives on local disk.

func (*Index) IsReadOnly

func (index *Index) IsReadOnly() bool

IsReadOnly reports whether the index rejects writes.

func (*Index) MarshalJSON

func (index *Index) MarshalJSON() ([]byte, error)

func (*Index) Reopen

func (index *Index) Reopen() error

Reopen just close the index, it will open automatically by trigger Deprecated: it will be removed in the future

func (*Index) Search

func (index *Index) Search(query *meta.ZedQuery) (*meta.SearchResponse, error)

func (*Index) SetAnalyzers

func (index *Index) SetAnalyzers(analyzers map[string]*analysis.Analyzer) error

func (*Index) SetMappings

func (index *Index) SetMappings(mappings *meta.Mappings) error

func (*Index) SetSettings

func (index *Index) SetSettings(settings *meta.IndexSettings) error

func (*Index) SnapshotTo

func (index *Index) SnapshotTo(dir string) ([]byte, error)

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) SyncWAL

func (index *Index) SyncWAL() error

SyncWAL flushes the open WAL of every shard to stable storage.

func (*Index) UpdateDocument

func (index *Index) UpdateDocument(docID string, doc map[string]interface{}, insert bool) error

UpdateDocument updates a document in the zed index

func (*Index) UpdateMetadata

func (index *Index) UpdateMetadata() error

UpdateMetadata update index metadata, mainly docNum and storageSize need merge from all first layer shards

func (*Index) UpdateMetadataByShard

func (index *Index) UpdateMetadataByShard(id string)

UpdateMetadataByShard update first layer shard metadata, mainly docNum, storageSize and timeRange need merge from all second layer shards

func (*Index) UpdateStatsBySecondShard

func (index *Index) UpdateStatsBySecondShard(id string, secondIndex int64)

UpdateStatsBySecondShard update second layer shard stats, mainly docNum and storageSize

func (*Index) UpdateWALSize

func (index *Index) UpdateWALSize(size uint64)

func (*Index) UseTemplate

func (index *Index) UseTemplate() error

func (*Index) WaitApplied

func (index *Index) WaitApplied(timeout time.Duration) error

WaitApplied waits until every WAL entry written before the call has been applied to the writers.

type IndexList

type IndexList struct {
	Indexes map[string]*Index
	// contains filtered or unexported fields
}
var ZED_INDEX_LIST IndexList

func (*IndexList) Add

func (t *IndexList) Add(index *Index)

func (*IndexList) Close

func (t *IndexList) Close() error

func (*IndexList) Delete

func (t *IndexList) Delete(name string)

func (*IndexList) GC

func (t *IndexList) GC() error

GC auto close unused indexes what inactive for a long time (10m)

func (*IndexList) Get

func (t *IndexList) Get(name string) (*Index, bool)

func (*IndexList) GetOrCreate

func (t *IndexList) GetOrCreate(name, storageType string, shardNum int64) (*Index, bool, error)

func (*IndexList) Len

func (t *IndexList) Len() int

func (*IndexList) List

func (t *IndexList) List() []*Index

func (*IndexList) ListMap

func (t *IndexList) ListMap() map[string]*Index

func (*IndexList) ListName

func (t *IndexList) ListName() []string

func (*IndexList) ListStat

func (t *IndexList) ListStat() []*Index

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 open WAL for index

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)

type M

type M map[string]interface{}

Jump to

Keyboard shortcuts

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