Documentation
¶
Overview ¶
- Copyright (C) 2017 Dgraph Labs, Inc. and Contributors *
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version. *
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details. *
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
Package posting takes care of posting lists. It contains logic for mutation layers, merging them with RocksDB, etc.
Package lru implements an LRU cache.
Index ¶
- Constants
- Variables
- func CommitLists(commit func(key []byte) bool)
- func DeleteAll() error
- func DeleteCountIndex(ctx context.Context, attr string) error
- func DeleteIndex(ctx context.Context, attr string) error
- func DeletePredicate(ctx context.Context, attr string) error
- func DeleteReverseEdges(ctx context.Context, attr string) error
- func EvictLRU()
- func Init(ps *badger.ManagedDB)
- func NewPosting(t *protos.DirectedEdge) *protos.Posting
- func Oracle() *oracle
- func RebuildCountIndex(ctx context.Context, attr string, startTs uint64)
- func RebuildIndex(ctx context.Context, attr string, startTs uint64)
- func RebuildReverseEdges(ctx context.Context, attr string, startTs uint64)
- func StopLRUEviction()
- func TxnMarks() *x.WaterMark
- func Txns() *transactions
- func TypeID(edge *protos.DirectedEdge) types.TypeID
- func UnmarshalOrCopy(val []byte, metadata byte, pl *protos.PostingList)
- type CacheStats
- type List
- func (l *List) AbortTransaction(ctx context.Context, startTs uint64) error
- func (l *List) AddMutation(ctx context.Context, txn *Txn, t *protos.DirectedEdge) (bool, error)
- func (l *List) AddMutationWithIndex(ctx context.Context, t *protos.DirectedEdge, txn *Txn) error
- func (l *List) AllValues(readTs uint64) (vals []types.Val, rerr error)
- func (l *List) AlreadyCommitted(startTs uint64) bool
- func (l *List) CommitMutation(ctx context.Context, startTs, commitTs uint64) error
- func (l *List) Conflicts(readTs uint64) []uint64
- func (l *List) EstimatedSize() int32
- func (l *List) Facets(readTs uint64, param *protos.Param, langs []string) (fs []*protos.Facet, ferr error)
- func (l *List) Iterate(readTs uint64, afterUid uint64, f func(obj *protos.Posting) bool) error
- func (l *List) Length(readTs, afterUid uint64) int
- func (l *List) MarshalToKv() (*protos.KV, error)
- func (l *List) Postings(opt ListOptions, postFn func(*protos.Posting) bool) error
- func (l *List) SetForDeletion() bool
- func (l *List) SyncIfDirty(delFromCache bool) (committed bool, err error)
- func (l *List) Uids(opt ListOptions) (*protos.List, error)
- func (l *List) Value(readTs uint64) (rval types.Val, rerr error)
- func (l *List) ValueFor(readTs uint64, langs []string) (rval types.Val, rerr error)
- func (l *List) ValueForTag(readTs uint64, tag string) (rval types.Val, rerr error)
- type ListOptions
- type Options
- type PIterator
- type Txn
- func (tx *Txn) AbortMutations(ctx context.Context) error
- func (t *Txn) AddDelta(key []byte, p *protos.Posting)
- func (tx *Txn) CommitMutations(ctx context.Context, commitTs uint64) error
- func (tx *Txn) CommitMutationsMemory(ctx context.Context, commitTs uint64) error
- func (t *Txn) Fill(ctx *protos.TxnContext)
- func (t *Txn) Index() uint64
- func (t *Txn) SetAbort()
- func (t *Txn) ShouldAbort() bool
Constants ¶
const ( // Set means overwrite in mutation layer. It contributes 0 in Length. Set uint32 = 0x01 // Del means delete in mutation layer. It contributes -1 in Length. Del uint32 = 0x02 // Metadata Bit which is stored to find out whether the stored value is pl or byte slice. BitUidPosting byte = 0x01 BitCompletePosting byte = 0x08 )
const (
MB = 1 << 20
)
Variables ¶
var ( // ErrRetry can be triggered if the posting list got deleted from memory due to a hard commit. // In such a case, retry. ErrRetry = fmt.Errorf("Temporary Error. Please retry.") // ErrNoValue would be returned if no value was found in the posting list. ErrNoValue = fmt.Errorf("No value found") ErrInvalidTxn = fmt.Errorf("Invalid transaction") )
var ( ErrConflict = x.Errorf("Conflicts with pending transaction") ErrTsTooOld = x.Errorf("Transaction is too old") )
Functions ¶
func CommitLists ¶
func EvictLRU ¶
func EvictLRU()
This doesn't sync, so call this only when you don't care about dirty posting lists in // memory(for example before populating snapshot) or after calling syncAllMarks
func NewPosting ¶
func NewPosting(t *protos.DirectedEdge) *protos.Posting
func RebuildIndex ¶
RebuildIndex rebuilds index for a given attribute. We commit mutations with startTs and ignore the errors.
func RebuildReverseEdges ¶
RebuildReverseEdges rebuilds the reverse edges for a given attribute.
func StopLRUEviction ¶
func StopLRUEviction()
func TypeID ¶
func TypeID(edge *protos.DirectedEdge) types.TypeID
TypeID returns the typeid of destination vertex
func UnmarshalOrCopy ¶
func UnmarshalOrCopy(val []byte, metadata byte, pl *protos.PostingList)
Copies the val if it's uid only posting, be careful
Types ¶
type CacheStats ¶
type List ¶
func Get ¶
Get stores the List corresponding to key, if it's not there already. to lru cache and returns it.
plist := Get(key, group) ... // Use plist TODO: This should take a node id and index. And just append all indices to a list. When doing a commit, it should update all the sync index watermarks. worker pkg would push the indices to the watermarks held by lists. And watermark stuff would have to be located outside worker pkg, maybe in x. That way, we don't have a dependency conflict.
func GetNoStore ¶
GetNoStore takes a key. It checks if the in-memory map has an updated value and returns it if it exists or it gets from the store and DOES NOT ADD to lru cache.
func ReadPostingList ¶
constructs the posting list from the disk using the passed iterator. Use forward iterator with allversions enabled in iter options.
func (*List) AbortTransaction ¶
func (*List) AddMutation ¶
AddMutation adds mutation to mutation layers. Note that it does not write anything to disk. Some other background routine will be responsible for merging changes in mutation layers to RocksDB. Returns whether any mutation happens.
func (*List) AddMutationWithIndex ¶
AddMutationWithIndex is AddMutation with support for indexing. It also supports reverse edges.
func (*List) AlreadyCommitted ¶
func (*List) CommitMutation ¶
func (*List) EstimatedSize ¶
func (*List) Facets ¶
func (l *List) Facets(readTs uint64, param *protos.Param, langs []string) (fs []*protos.Facet, ferr error)
Facets gives facets for the posting representing value.
func (*List) Iterate ¶
Iterate will allow you to iterate over this Posting List, while having acquired a read lock. So, please keep this iteration cheap, otherwise mutations would get stuck. The iteration will start after the provided UID. The results would not include this UID. The function will loop until either the Posting List is fully iterated, or you return a false in the provided function, which will indicate to the function to break out of the iteration.
pl.Iterate(func(p *protos.Posting) bool { // Use posting p return true // to continue iteration. return false // to break iteration. })
func (*List) Postings ¶
Postings calls postFn with the postings that are common with uids in the opt ListOptions.
func (*List) SetForDeletion ¶
SetForDeletion will mark this List to be deleted, so no more mutations can be applied to this.
func (*List) SyncIfDirty ¶
func (*List) Uids ¶
func (l *List) Uids(opt ListOptions) (*protos.List, error)
Uids returns the UIDs given some query params. We have to apply the filtering before applying (offset, count). WARNING: Calling this function just to get Uids is expensive
func (*List) Value ¶
Returns Value from posting list. This function looks only for "default" value (one without language).
func (*List) ValueFor ¶
Returns Value from posting list, according to preferred language list (langs). If list is empty, value without language is returned; if such value is not available, value with smallest Uid is returned. If list consists of one or more languages, first available value is returned; if no language from list match the values, processing is the same as for empty list.
type ListOptions ¶
type ListOptions struct { ReadTs uint64 AfterUID uint64 // Any UID returned must be after this value. Intersect *protos.List // Intersect results with this list of UIDs. }
ListOptions is used in List.Uids (in posting) to customize our output list of UIDs, for each posting list. It should be internal to this package.
type Txn ¶
type Txn struct { StartTs uint64 // Fields which can changed after init sync.Mutex // Stores list of proposal indexes belonging to the transaction, the watermark would // be marked as done only when it's committed. Indices []uint64 // contains filtered or unexported fields }
func (*Txn) CommitMutations ¶
Don't call this for schema mutations. Directly commit them.
func (*Txn) CommitMutationsMemory ¶
func (*Txn) Fill ¶
func (t *Txn) Fill(ctx *protos.TxnContext)