dgraph-io / dgraph-io/badger

Allow users to explicitly mark keys as not eligible for Garbage Collection

Open
#2,192 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Stale
Dominant language
Go
Stars
15.8k
Forks
1.3k
Avg merge
2m
Merged PRs (30d)
1

Description

Is your feature request related to a problem? Please describe

In managed mode, a user may want to mark keys as not eligible for garbage collection.

With the following conditions:

  • KeepNumVersions=MaxInt64
  • DiscardTs > KeyTs
  • deleted or expired key at a higher Ts

A key will be eligible for garbage collection.

Describe the solution you'd like

Expose a method in Entry that allows users in Managed Mode to set a Never Discard bit.

// WithNeverDiscard sets merge bit in entry's metadata. This
// prevents the compactor from marking the key eligible for GC.
func (e *Entry) WithNeverDiscard() *Entry {
	e.meta = bitMergeEntry // this works -- but could use another bit
	return e
}

Describe alternatives you've considered

Allow users to explicitly mark keys eligible for garbage collection when DiscardTs is unset.

Additional context

This is useful when users want to leverage the Multi-Version system of BadgerDB in Managed Mode to maintain multiple versions of keys.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing Entry metadata handling and the compactor logic that marks keys eligible for garbage collection in managed mode. Review the existing merge-bit behavior and determine how a never-discard marker should interact with the listed version and timestamp conditions. Done means users can set the marker through Entry and those keys are excluded from GC, with coverage for the described case.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.