Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix discard stats moved by GC bug #929

Merged
merged 9 commits into from
Jul 18, 2019
Merged

Conversation

jarifibrahim
Copy link
Contributor

@jarifibrahim jarifibrahim commented Jul 13, 2019

The discard stats are stored like normal keys in badger, which means if
the size of the value of discard stats key is greater the value threshold it
will be stored in the value log. When value log GC happens, we insert
the same key in badger with a !badger!move prefix which points to the
new value log file. So when searching for the value of a key, if the value
points to a value log file which doesn't exist, we search for the same
key with !badger!move prefix.

The above logic was missing from the populateDiscardStats function. The
earlier implementation would never search for the key with !badger!move
prefix. It would return error on the first attempt to find the key. This
commit ensures we search for a key with prefix badger move if the value
for the existing key pointed to a value log file that no longer exists.

Fixes - #926


This change is Reviewable

Ibrahim Jarif added 6 commits July 13, 2019 23:43
The discard stats are stored like normal keys in badger, which means if
the size of value of discard stats key is greater the value threshold it
will be stored in the value log. When value log GC happens, we insert
the same key in badger with a !badger!move prefix which points to the
new value log file. So when searching for the value of a key, if the value
points to a value log file which doesn't exist, we search for the same
key with !badger!move prefix.

The above logic was missing from the populateDiscardStats function. The
earlier implementation would never search for the key with !badger!move
prefix. It would return error on first attempt to find the key. This
commit ensures we search for key with prefix badger move if the value
for the existing key pointed to a value log file that no longer exist.
@jarifibrahim jarifibrahim marked this pull request as ready for review July 13, 2019 19:57
@jarifibrahim jarifibrahim requested a review from poonai July 15, 2019 12:05
Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 2 of 2 files at r1.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @ashish-goswami, @jarifibrahim, and @Sch00lb0y)


value.go, line 1431 at r1 (raw file):

func (vlog *valueLog) populateDiscardStats() error {
	key := y.KeyWithTs(lfDiscardStatsKey, math.MaxUint64)
	newKey := make([]byte, len(key))

Don't need newKey


value.go, line 1449 at r1 (raw file):

		// Entry stored in LSM tree.
		if vs.Meta&bitValuePointer == 0 {
			val = make([]byte, len(vs.Value))

val = y.SafeCopy(vs.Value)


value.go, line 1454 at r1 (raw file):

		}
		// Read entry from value log.
		result, cb, err := vlog.Read(vp, new(y.Slice))

Just confirm that you can defer run callback without checking error.


value.go, line 1456 at r1 (raw file):

		result, cb, err := vlog.Read(vp, new(y.Slice))
		defer runCallback(cb)
		val = make([]byte, len(result))

val = y.SafeCopy(result)


value.go, line 1472 at r1 (raw file):

		// Prepend existing key with badger move and search for the key.
		n := copy(newKey, badgerMove)
		copy(newKey[n:], key)

key = append(badgerMove, key...)?


value.go, line 1479 at r1 (raw file):

	}
	if err := json.Unmarshal(val, &statsMap); err != nil {
		return errors.Wrapf(err, "failed to unmarshal discard stats")

Just log it. And continue the logic.

@connorgorman
Copy link
Contributor

Will this PR be cherry-picked on top of 1.6 and released as v1.6.1? Currently without this change, v1.6.0 has an unrepairable issue.

@jarifibrahim
Copy link
Contributor Author

Will this PR be cherry-picked on top of 1.6 and released as v1.6.1? Currently without this change, v1.6.0 has an unrepairable issue.

@campoy How should we release this fix?

Copy link
Contributor Author

@jarifibrahim jarifibrahim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @ashish-goswami, @manishrjain, and @Sch00lb0y)


value.go, line 1431 at r1 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

Don't need newKey

Done.


value.go, line 1449 at r1 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

val = y.SafeCopy(vs.Value)

Done.


value.go, line 1454 at r1 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

Just confirm that you can defer run callback without checking error.

The callback is nothing but a lockfile.Lock.Unlock() function. Even in case of error, we should unlock the file. The call should be called before we handle the error.


value.go, line 1456 at r1 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

val = y.SafeCopy(result)

Done.


value.go, line 1472 at r1 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

key = append(badgerMove, key...)?

Done.


value.go, line 1479 at r1 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

Just log it. And continue the logic.

This change is in #936 . I'll update this branch once #936 is merged.

@jarifibrahim jarifibrahim merged commit 50c90ed into master Jul 18, 2019
@jarifibrahim jarifibrahim deleted the ibrahim/discardstats-gc branch July 18, 2019 18:21
jurriaan added a commit to blendle/badger that referenced this pull request Jul 31, 2019
akehlenbeck pushed a commit to lightstep/badger that referenced this pull request Oct 15, 2019
* Fix discard stats moved by GC bug

The discard stats are stored like normal keys in badger, which means if
the size of the value of discard stats key is greater the value threshold it
will be stored in the value log. When value log GC happens, we insert
the same key in badger with a !badger!move prefix which points to the
new value log file. So when searching for the value of a key, if the value
points to a value log file which doesn't exist, we search for the same
key with !badger!move prefix.

The above logic was missing from the populateDiscardStats function. The
earlier implementation would never search for the key with !badger!move
prefix. It would return error on the first attempt to find the key. This
commit ensures we search for a key with prefix badger move if the value
for the existing key pointed to a value log file that no longer exists.
akehlenbeck added a commit to lightstep/badger that referenced this pull request Oct 15, 2019
jarifibrahim pushed a commit that referenced this pull request Oct 24, 2019
The discard stats are stored like normal keys in badger, which means if
the size of the value of discard stats key is greater the value threshold it
will be stored in the value log. When value log GC happens, we insert
the same key in badger with a !badger!move prefix which points to the
new value log file. So when searching for the value of a key, if the value
points to a value log file which doesn't exist, we search for the same
key with !badger!move prefix.

The above logic was missing from the populateDiscardStats function. The
earlier implementation would never search for the key with !badger!move
prefix. It would return error on the first attempt to find the key. This
commit ensures we search for a key with prefix badger move if the value
for the existing key pointed to a value log file that no longer exists.
jarifibrahim pushed a commit that referenced this pull request Oct 24, 2019
The discard stats are stored like normal keys in badger, which means if
the size of the value of discard stats key is greater the value threshold it
will be stored in the value log. When value log GC happens, we insert
the same key in badger with a !badger!move prefix which points to the
new value log file. So when searching for the value of a key, if the value
points to a value log file which doesn't exist, we search for the same
key with !badger!move prefix.

The above logic was missing from the populateDiscardStats function. The
earlier implementation would never search for the key with !badger!move
prefix. It would return error on the first attempt to find the key. This
commit ensures we search for a key with prefix badger move if the value
for the existing key pointed to a value log file that no longer exists.
jarifibrahim pushed a commit that referenced this pull request Oct 24, 2019
The discard stats are stored like normal keys in badger, which means if
the size of the value of discard stats key is greater the value threshold it
will be stored in the value log. When value log GC happens, we insert
the same key in badger with a !badger!move prefix which points to the
new value log file. So when searching for the value of a key, if the value
points to a value log file that doesn't exist, we search for the same
key with !badger!move prefix.

The above logic was missing from the populateDiscardStats function. The
earlier implementation would never search for the key with !badger!move
prefix. It would return error on the first attempt to find the key. This
commit ensures we search for a key with prefix badger move if the value
for the existing key pointed to a value log file that no longer exists.
danielmai added a commit to dgraph-io/dgraph that referenced this pull request Oct 24, 2019
This vendors in Badger v1.6.0 with dgraph-io/badger#929 cherry-picked
into it (dgraph-io/badger#1098) to avoid any breaking changes to the
data format.
danielmai added a commit to dgraph-io/dgraph that referenced this pull request Oct 24, 2019
This vendors in Badger v1.6.0 with dgraph-io/badger#929 cherry-picked
into it (dgraph-io/badger#1098) to avoid any breaking changes to the
data format.

Vendor in Badger to fix a bug that prevents Alpha from starting
up successfully. This happens in v1.0.16 and v1.0.17.

    Error while creating badger KV posting store error: Unable to find log file. Please retry

The release/v1.0 branch uses the vendor directory for
dependencies. Badger was pulled in with the following command:

    govendor fetch github.com/dgraph-io/badger/...@efb9d9d15d7f7baa656e04933058f006c33a8d0f
danielmai added a commit to dgraph-io/dgraph that referenced this pull request Oct 24, 2019
This vendors in Badger v1.6.0 with dgraph-io/badger#929 cherry-picked
into it (dgraph-io/badger#1098) to avoid any breaking changes to the
data format.

Vendor in Badger to fix a bug that prevents Alpha from starting
up successfully. This happens in v1.0.16 and v1.0.17.

    Error while creating badger KV posting store error: Unable to find log file. Please retry

The release/v1.0 branch uses the vendor directory for
dependencies. Badger was pulled in with the following command:

    govendor fetch github.com/dgraph-io/badger/...@efb9d9d15d7f7baa656e04933058f006c33a8d0f
ita-sammann added a commit to insolar/badger that referenced this pull request Oct 31, 2019
qcollapse pushed a commit to aergoio/aergo-lib that referenced this pull request Jan 28, 2020
qcollapse pushed a commit to aergoio/aergo-lib that referenced this pull request Feb 6, 2020
- The actual package is the forked version from the Badger release/1.6
  branch to avoid a build failure resulting from the modification of
  the Badger repository like branch removing.
- For the details, see dgraph-io/badger#929
jarifibrahim pushed a commit that referenced this pull request Mar 12, 2020
* Fix discard stats moved by GC bug

The discard stats are stored like normal keys in badger, which means if
the size of the value of discard stats key is greater the value threshold it
will be stored in the value log. When value log GC happens, we insert
the same key in badger with a !badger!move prefix which points to the
new value log file. So when searching for the value of a key, if the value
points to a value log file which doesn't exist, we search for the same
key with !badger!move prefix.

The above logic was missing from the populateDiscardStats function. The
earlier implementation would never search for the key with !badger!move
prefix. It would return error on the first attempt to find the key. This
commit ensures we search for a key with prefix badger move if the value
for the existing key pointed to a value log file that no longer exists.

(cherry picked from commit 50c90ed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants