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

RunValueLogGC crashed #1139

Closed
cedricfung opened this issue Nov 28, 2019 · 46 comments
Closed

RunValueLogGC crashed #1139

cedricfung opened this issue Nov 28, 2019 · 46 comments
Labels
area/crash This issue causes a panic or some other of exception that causes a crash. kind/maintenance Maintenance tasks, such as refactoring, with no impact in features. priority/P1 Serious issue that requires eventual attention (can wait a bit) status/accepted We accept to investigate or work on it.

Comments

@cedricfung
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.13.4 linux/amd64

What version of Badger are you using?

v2.0.0

Does this issue reproduce with the latest master?

Never tried

What are the hardware specifications of the machine (RAM, OS, Disk)?

Linux 64 SSD

What did you do?

	opts := badger.DefaultOptions(dir)
	opts.SyncWrites = sync
	db, err := badger.Open(opts)
	if err != nil {
		return nil, err
	}
	db.RunValueLogGC(0.1)

	go func() {
		ticker := time.NewTicker(1 * time.Minute)
		defer ticker.Stop()
		for range ticker.C {
			lsm, vlog := db.Size()
			if lsm > 1024*1024*8 || vlog > 1024*1024*32 {
				db.RunValueLogGC(0.5)
			}
		}
	}()

What did you expect to see?

Run value log gc should work

What did you see instead?

mixin[28404]: github.com/dgraph-io/badger/v2/y.AssertTrue
mixin[28404]:         /home/one/GOPATH/pkg/mod/github.com/dgraph-io/badger/[email protected]/y/error.go:55
mixin[28404]: github.com/dgraph-io/badger/v2.(*valueLog).doRunGC.func2
mixin[28404]:         /home/one/GOPATH/pkg/mod/github.com/dgraph-io/badger/[email protected]/value.go:1591
mixin[28404]: github.com/dgraph-io/badger/v2.(*valueLog).iterate
mixin[28404]:         /home/one/GOPATH/pkg/mod/github.com/dgraph-io/badger/[email protected]/value.go:480
mixin[28404]: github.com/dgraph-io/badger/v2.(*valueLog).doRunGC
mixin[28404]:         /home/one/GOPATH/pkg/mod/github.com/dgraph-io/badger/[email protected]/value.go:1557
mixin[28404]: github.com/dgraph-io/badger/v2.(*valueLog).runGC
mixin[28404]:         /home/one/GOPATH/pkg/mod/github.com/dgraph-io/badger/[email protected]/value.go:1685
mixin[28404]: github.com/dgraph-io/badger/v2.(*DB).RunValueLogGC
mixin[28404]:         /home/one/GOPATH/pkg/mod/github.com/dgraph-io/badger/[email protected]/db.go:1129
mixin[28404]: github.com/MixinNetwork/mixin/storage.openDB.func1
mixin[28404]:         /home/one/github/mixin/storage/badger.go:68
mixin[28404]: runtime.goexit
mixin[28404]:         /snap/go/4762/src/runtime/asm_amd64.s:1357

badger.go:68 db.RunValueLogGC(0.5)

@lgalatin lgalatin added the area/crash This issue causes a panic or some other of exception that causes a crash. label Dec 3, 2019
@jarifibrahim
Copy link
Contributor

Hey @cedricfung , does the issue reproduce after a couple of hours? And do you have more badger logs? The logs you've posted show only the line on which the crash happened but I'd like to understand what the state of badger was when the crash happened. Logs would definitely have some more information.

@jarifibrahim jarifibrahim added kind/bug Something is broken. priority/P1 Serious issue that requires eventual attention (can wait a bit) status/more-info-needed The issue has been sent back to the reporter asking for clarifications labels Dec 6, 2019
@cedricfung
Copy link
Author

Hi, I have tried again, it crashes. Our code is https://github.com/MixinNetwork/mixin

badger 2019/12/07 13:23:28 INFO: All 105 tables opened in 2.049s
badger 2019/12/07 13:23:28 INFO: Replaying file id: 168 at offset: 215041567
badger 2019/12/07 13:23:30 INFO: Replay took: 1.677080583s
badger 2019/12/07 13:23:30 INFO: Replaying file id: 169 at offset: 0
badger 2019/12/07 13:23:32 DEBUG: Flushing memtable, mt.size=67108931 size of flushChan: 0
badger 2019/12/07 13:23:32 DEBUG: Storing value log head: {Fid:0 Len:0 Offset:0}
badger 2019/12/07 13:23:33 INFO: Replay took: 3.373910494s
badger 2019/12/07 13:23:33 INFO: Replaying file id: 170 at offset: 0
badger 2019/12/07 13:23:35 DEBUG: Flushing memtable, mt.size=67108936 size of flushChan: 0
badger 2019/12/07 13:23:35 DEBUG: Storing value log head: {Fid:0 Len:0 Offset:0}
badger 2019/12/07 13:23:36 INFO: Replay took: 3.082134609s
badger 2019/12/07 13:23:36 INFO: Replaying file id: 171 at offset: 0
badger 2019/12/07 13:23:37 DEBUG: Flushing memtable, mt.size=67108868 size of flushChan: 0
badger 2019/12/07 13:23:37 DEBUG: Storing value log head: {Fid:0 Len:0 Offset:0}
badger 2019/12/07 13:23:39 INFO: Replay took: 2.145432608s
badger 2019/12/07 13:23:39 DEBUG: Value log discard stats empty
badger 2019/12/07 13:23:43 INFO: All 0 tables opened in 0s
badger 2019/12/07 13:23:43 INFO: Replaying file id: 0 at offset: 0
badger 2019/12/07 13:23:44 INFO: Replay took: 917.803776ms
badger 2019/12/07 13:23:44 DEBUG: Value log discard stats empty
badger 2019/12/07 13:23:44 INFO: All 1 tables opened in 1ms
badger 2019/12/07 13:23:44 INFO: Replaying file id: 0 at offset: 82
badger 2019/12/07 13:23:44 INFO: Replay took: 2.879µs
badger 2019/12/07 13:23:44 DEBUG: Value log discard stats empty


2019/12/07 13:30:44 Assert failed
github.com/dgraph-io/badger/v2/y.AssertTrue
	/home/one/GOPATH/pkg/mod/github.com/dgraph-io/badger/[email protected]/y/error.go:55
github.com/dgraph-io/badger/v2.(*valueLog).doRunGC.func2
	/home/one/GOPATH/pkg/mod/github.com/dgraph-io/badger/[email protected]/value.go:1591
github.com/dgraph-io/badger/v2.(*valueLog).iterate
	/home/one/GOPATH/pkg/mod/github.com/dgraph-io/badger/[email protected]/value.go:480
github.com/dgraph-io/badger/v2.(*valueLog).doRunGC
	/home/one/GOPATH/pkg/mod/github.com/dgraph-io/badger/[email protected]/value.go:1557
github.com/dgraph-io/badger/v2.(*valueLog).runGC
	/home/one/GOPATH/pkg/mod/github.com/dgraph-io/badger/[email protected]/value.go:1685
github.com/dgraph-io/badger/v2.(*DB).RunValueLogGC
	/home/one/GOPATH/pkg/mod/github.com/dgraph-io/badger/[email protected]/db.go:1129
github.com/MixinNetwork/mixin/storage.openDB.func1
	/home/one/github/mixin/storage/badger.go:68
runtime.goexit
	/snap/go/4901/src/runtime/asm_amd64.s:1357

Above is the full log

@jarifibrahim
Copy link
Contributor

@cedricfung are you inserting nil values? Something like txn.Set("key", nil)

@jarifibrahim jarifibrahim added kind/maintenance Maintenance tasks, such as refactoring, with no impact in features. and removed kind/bug Something is broken. labels Dec 9, 2019
@cedricfung
Copy link
Author

cedricfung commented Dec 9, 2019 via email

@jarifibrahim
Copy link
Contributor

The txn.Set("key", []byte{}) seems to be causing the issue. We have a check which ensures value length is greater than zero. That check seems to be causing the failure.

@jarifibrahim
Copy link
Contributor

Hey @cedricfung, just out of curiosity, why are you inserting empty values? What are you trying to accomplish with key-only badger?

@cedricfung
Copy link
Author

Hi @jarifibrahim, I want to maintain many states to indicate that we have those keys set. So they are actually some bool values. I have thought those key only writes and reads would be faster with badger.

@jarifibrahim
Copy link
Contributor

jarifibrahim commented Dec 10, 2019

@cedricfung how can I run https://github.com/MixinNetwork/mixin and reproduce the issue? I just realized that we have a check in badger for empty values and the execution shouldn't have reached the line on which it crashed for you.

@cedricfung
Copy link
Author

  1. git clone https://github.com/MixinNetwork/mixin
  2. git checkout fd33f483f7b5d0
  3. mkdir ~/mixin-data
  4. cp config/genesis.json config/nodes.json ~/mixin-data
  5. cp config/config.example.json ~/mixin-data
  6. go build
  7. ./mixin kernel -dir ~/mixin-data -port 7239
  8. Ctrl+C to stop the process
  9. rm -rf ~/mixin-data/snapshots
  10. Get the data http://35.188.235.212/snapshots.tar
  11. tar xvf snapshots.tar
  12. mv snapshots ~/mixin-data
  13. ./mixin kernel -dir ~/mixin-data -port 7239

Ignore other connection logs and wating for about 10 minutes, it should crash.

@jarifibrahim
Copy link
Contributor

@cedricfung Is there any way I can reproduce this without using your snapshot directory? The issue is visible on your directory but I'm trying to figure out how did such an entry (which has bitvaluepointer set and has zero length) was inserted into badger.

@cedricfung
Copy link
Author

I don't know yet. Which entry is that?

@jarifibrahim
Copy link
Contributor

Sorry, I wasn't clear. My question is does the issue show up every time you run your mixin project? There is an invalid entry in your badger directory and I'm trying to figure out how was that entry inserted.

@cedricfung
Copy link
Author

It only produces the error on that snapshots data, for a fresh start it won't occur.

@cedricfung
Copy link
Author

Forgot to mention that the snapshots directory is converted from an old version. I upgraded badger from an 2.0-rc version to the latest 2.0 version, following the guide of upgrade from v1.6 to v2.0

@jarifibrahim
Copy link
Contributor

Ah! Maybe backup is doing something mischievous. I'll look into the backup code and get back to you.

@cedricfung
Copy link
Author

Any updates on this? How could we enable RunValueLogGC again?

@lgalatin lgalatin added status/accepted We accept to investigate or work on it. and removed status/more-info-needed The issue has been sent back to the reporter asking for clarifications labels Jan 3, 2020
@jarifibrahim
Copy link
Contributor

@cedricfung Unfortunately, I haven't been able to find a test to produce this. I can, however, write a patch for you which will drop the key which seems to be crashing badger. You can run badger with that patch and GC should work fine.

NOTE - You might lose data. I think you just have one key which has the wrong bits set and we'll have to drop it.

Do you think this would unblock you for now?

@cedricfung
Copy link
Author

Which key is that? I'm sure that we have many keys with empty values, because we have code like err = txn.Set(key, []byte{})

@jarifibrahim
Copy link
Contributor

Hey @cedricfung, I haven't been able to find the root cause for this issue but you can use the following diff to clean up the invalid bit set. Here's how you can use it
(Please make a copy of your original data before you run the following commands. I've tested them but in case something goes wrong, we'll still have the original data)

  1. Fetch badger and make sure you have the latest master
  2. git apply diff.patch
  3. Run go build/ go install
  4. Run ./badger backup --dir /path/to/your/snapshot/directory
  5. Run ./badger restore --dir /path/to/a/new/directory backup.bak

We created a backup that removed the bitValuePointer for the invalid entries and we restored the backup. So now the new data does not have any invalid entries.

(The patch also disables compression. This would reduce the time taken to restore the backup)

diff --git a/backup.go b/backup.go
index aa03339..ebab32f 100644
--- a/backup.go
+++ b/backup.go
@@ -59,14 +59,20 @@ func (stream *Stream) Backup(w io.Writer, since uint64) (uint64, error) {
 			}
 
 			var valCopy []byte
+			// No need to copy value, if item is deleted or expired.
 			if !item.IsDeletedOrExpired() {
-				// No need to copy value, if item is deleted or expired.
-				var err error
-				valCopy, err = item.ValueCopy(nil)
-				if err != nil {
-					stream.db.opt.Errorf("Key [%x, %d]. Error while fetching value [%v]\n",
-						item.Key(), item.Version(), err)
-					return nil, err
+				if item.meta&bitValuePointer > 0 && len(item.val) == 0 {
+					// This entry has wrong bit set. Unset the `bitValuePoiter` bit.
+					item.meta = item.meta &^ (bitValuePointer)
+				} else {
+					// This is a valid entry. Copy its value.
+					var err error
+					valCopy, err = item.ValueCopy(nil)
+					if err != nil {
+						stream.db.opt.Errorf("Key [%x, %d]. Error while fetching value [%v]\n",
+							item.Key(), item.Version(), err)
+						return nil, err
+					}
 				}
 			}
 
diff --git a/options.go b/options.go
index 4374fc3..0bb9699 100644
--- a/options.go
+++ b/options.go
@@ -107,6 +107,9 @@ func DefaultOptions(path string) Options {
 	if !y.CgoEnabled {
 		defaultCompression = options.Snappy
 	}
+
+	defaultCompression = options.None
+
 	return Options{
 		Dir:                 path,
 		ValueDir:            path,

I ran the same patch on the data directory provided by @cedricfung and all the invalid entries were fixed.

@jarifibrahim
Copy link
Contributor

Closing this issue since it is not reproducible. The invalid entries might have been added somehow in the older version of badger (I guess).

Please re-open this issue if it shows up again.

@cedricfung
Copy link
Author

Hi @jarifibrahim will this process remove any entries? We need to keep all entries, even empty entries.

@jarifibrahim
Copy link
Contributor

@cedricfung No. It would not. The code above would take a backup of your current badger directory and unset the bit which was causing the issue. We're reinserting all the entries when you restore that backup.

The process should not cause any data to be lost since your values are nil. However, please make a copy of your existing data. It might help if something goes wrong :)

@cedricfung
Copy link
Author

Thank you. I'm curious about the backup file size, my data is 47GB, and the backup is only 11GB, but the backup of v1.6 is 37GB. Is this normal?

@cedricfung
Copy link
Author

After I restored the data, the directory is only 20GB. And my program can't start with this new data set.

@jarifibrahim
Copy link
Contributor

Thank you. I'm curious about the backup file size, my data is 47GB, and the backup is only 11GB, but the backup of v1.6 is 37GB. Is this normal?

The size reduction is expected because backup uses protobuf to store data which is supposed to reduce the disk space.

but the backup of v1.6 is 37GB.

There shouldn't be such a huge size difference between v1.6.0 and v2.0.0
How did you take the backup? The directory you've shared in #1139 (comment) wouldn't work with badger v1.6.

After I restored the data, the directory is only 20GB. And my program can't start with this new data set.

Are you able to open badger directory? Can you show me some logs?

@cedricfung
Copy link
Author

How did you take the backup? The directory you've shared in #1139 (comment) wouldn't work with badger v1.6.

I have kept the old backup from v1.6, so I compared the size.

I tried the steps again and get the same error. The database opened, but I think some value lost. The error is:

	copy(publicSpend[:], ival[:len(publicSpend)])
panic: runtime error: slice bounds out of range [:32] with capacity 0

So it means the ival has zero length, it should have at least 32 bytes.

@jarifibrahim
Copy link
Contributor

I tried the steps again and get the same error. The database opened, but I think some value lost. The error is:

	copy(publicSpend[:], ival[:len(publicSpend)])
panic: runtime error: slice bounds out of range [:32] with capacity 0

So it means the ival has zero length, it should have at least 32 bytes.

Was this value read from badger? If badger has zero-length values, why does this code need 32 bytes?

@cedricfung
Copy link
Author

This value read from badger. This value should have 64 bytes before those steps. It has 64 bytes in the original dataset.

@jarifibrahim
Copy link
Contributor

@cedricfung Can you check the length of the value returned by badger? If badger is returning an empty value, your code should work fine. Is that right?

@cedricfung
Copy link
Author

It should not return an empty value. Before I run the process of backup and restore, the value is at least 32 bytes. After the process, the value is zero length, or maybe the entry is missing. E.g. the backup and restore steps have lost some data.

The old snapshots data is about 47GB, after the process it's only 20GB. And the new data has no compression, but the old has compression. So I think there must be large quantity of entries lost.

@jarifibrahim
Copy link
Contributor

The old snapshots data is about 47GB, after the process, it's only 20GB. And the new data has no compression, but the old has compression. So I think there must be a large quantity of entries lost.

@cedricfung the original data would have some invalid data too. For instance, the keys which were deleted would be stored on the disk but they would be dropped after backup-restore. I had run the patch on my end on your directory and most of the keys were present in the new data. Let me double-check this. Some internal keys would be dropped and that's okay.

It should not return an empty value.

As you mentioned in this comment #1139 (comment), you're inserting []byte{} which is a zero-length byte array. If you insert a zero-length value, badger would return a zero-length value array. Am I missing something here?

@cedricfung
Copy link
Author

I'm inserting []byte{} entries, but it is not this entry. I'm sure that this entry should have at least 32 bytes value. This exact entry is not empty.

@cedricfung
Copy link
Author

Hi @jarifibrahim any updates on this?

@jarifibrahim jarifibrahim reopened this Feb 7, 2020
@jarifibrahim
Copy link
Contributor

Hey @cedricfung , sorry it took me so long to reply.
Can you help me understand what do you mean by

I'm inserting []byte{} entries, but it is not this entry. I'm sure that this entry should have at least 32 bytes value. This exact entry is not empty.

Initially, I understood that you're inserting zero-length values in badger, but I guess that's not the case.
Are you saying that you inserted 32 bytes long values and received zero-length values back?
I tried to look at the code of https://github.com/MixinNetwork/mixin to figure out what's going on but lost my way around the codebase.

@cedricfung
Copy link
Author

cedricfung commented Feb 7, 2020 via email

@jarifibrahim
Copy link
Contributor

Hey @cedricfung, I ran the following patch (I made one small change so that we don't delete any key. We'll keep even the deleted/discard ones on restore) on the snapshots.tar you had sent.
I can confirm the number of keys in the snapshots directory before clean up and after clean up is the same.

In your snapshots directory

 ~/mixin-data/snapshots  ll -S | head                                       
total 42G
-rw------- 1 ibrahim ibrahim 1.1G Feb 10 19:14 000167.vlog
-rw------- 1 ibrahim ibrahim 914M Feb 10 19:16 000166.vlog
-rw------- 1 ibrahim ibrahim 717M Feb 10 19:15 000163.vlog
-rw------- 1 ibrahim ibrahim 606M Feb 10 19:16 000162.vlog
-rw------- 1 ibrahim ibrahim 515M Feb 10 19:15 000161.vlog
-rw------- 1 ibrahim ibrahim 445M Feb 10 19:15 000098.vlog
-rw------- 1 ibrahim ibrahim 435M Feb 10 19:13 000164.vlog
-rw------- 1 ibrahim ibrahim 408M Feb 10 19:16 000153.vlog
-rw------- 1 ibrahim ibrahim 407M Feb 10 19:16 000074.vlog

  • Total Number of keys: 177,148,831
  • Total Number of Unique Keys: 153, 839, 227
  • Total Number of Invalid keys: 12, 797, 570

In the badger directory generated after backup-restore

~/mixin-data/snapshots-new  ll -S | head
total 19G
-rw------- 1 ibrahim ibrahim  70M Feb 10 19:39 001234.sst
-rw------- 1 ibrahim ibrahim  70M Feb 10 19:39 001228.sst
-rw------- 1 ibrahim ibrahim  70M Feb 10 19:39 001232.sst
-rw------- 1 ibrahim ibrahim  70M Feb 10 19:39 001230.sst
-rw------- 1 ibrahim ibrahim  69M Feb 10 19:33 000014.vlog
-rw------- 1 ibrahim ibrahim  69M Feb 10 19:37 001033.sst
-rw------- 1 ibrahim ibrahim  69M Feb 10 19:37 001072.sst
-rw------- 1 ibrahim ibrahim  69M Feb 10 19:37 001069.sst
-rw------- 1 ibrahim ibrahim  69M Feb 10 19:37 001075.sst

  • Total Number of keys: 177,148,831
  • Total Number of Unique Keys: 153, 839, 227
  • Total Number of Invalid keys: 0

I am not sure why the directory sizes defer by so much but as long as all the keys are present in the new badger directory, we should be fine.

Please try out this patch and let me know how it goes

diff --git a/backup.go b/backup.go
index aa03339..97b469c 100644
--- a/backup.go
+++ b/backup.go
@@ -59,14 +59,18 @@ func (stream *Stream) Backup(w io.Writer, since uint64) (uint64, error) {
 			}
 
 			var valCopy []byte
+			// No need to copy value, if item is deleted or expired.
 			if !item.IsDeletedOrExpired() {
-				// No need to copy value, if item is deleted or expired.
-				var err error
-				valCopy, err = item.ValueCopy(nil)
-				if err != nil {
-					stream.db.opt.Errorf("Key [%x, %d]. Error while fetching value [%v]\n",
-						item.Key(), item.Version(), err)
-					return nil, err
+				if item.meta&bitValuePointer > 0 && len(item.val) == 0 {
+					item.meta = item.meta &^ (bitValuePointer)
+				} else {
+					var err error
+					valCopy, err = item.ValueCopy(nil)
+					if err != nil {
+						stream.db.opt.Errorf("Key [%x, %d]. Error while fetching value [%v]\n",
+							item.Key(), item.Version(), err)
+						return nil, err
+					}
 				}
 			}
 
diff --git a/badger/cmd/backup.go b/badger/cmd/backup.go
index 79fa9fd..189c296 100644
--- a/badger/cmd/backup.go
+++ b/badger/cmd/backup.go
@@ -18,6 +18,7 @@ package cmd
 
 import (
 	"bufio"
+	"math"
 	"os"
 
 	"github.com/dgraph-io/badger/v2"
@@ -53,7 +54,8 @@ func doBackup(cmd *cobra.Command, args []string) error {
 	// Open DB
 	db, err := badger.Open(badger.DefaultOptions(sstDir).
 		WithValueDir(vlogDir).
-		WithTruncate(truncate))
+		WithTruncate(truncate).WithNumVersionsToKeep(math.MaxUint32))
+
 	if err != nil {
 		return err
 	}
diff --git a/badger/cmd/restore.go b/badger/cmd/restore.go
index d5ee8f5..ee074f3 100644
--- a/badger/cmd/restore.go
+++ b/badger/cmd/restore.go
@@ -18,6 +18,7 @@ package cmd
 
 import (
 	"errors"
+	"math"
 	"os"
 	"path"
 
@@ -65,7 +66,8 @@ func doRestore(cmd *cobra.Command, args []string) error {
 	}
 
 	// Open DB
-	db, err := badger.Open(badger.DefaultOptions(sstDir).WithValueDir(vlogDir))
+	db, err := badger.Open(badger.DefaultOptions(sstDir).
+		WithValueDir(vlogDir).WithNumVersionsToKeep(math.MaxUint32))
 	if err != nil {
 		return err
 	}

@jarifibrahim
Copy link
Contributor

You can use this test to count the number of keys (put it anywhere in the badger directory)

var dir1 string = "/home/ibrahim/mixin-data/snapshots"    
    
func TestDumpKey(t *testing.T) {    
    opt := DefaultOptions(dir1)    
    opt.NumVersionsToKeep = math.MaxUint32    
    //opt.ReadOnly = true    
    
    db, err := Open(opt)       
    require.NoError(t, err)    
    
    txn := db.NewTransaction(false)    
    defer txn.Discard()    
    
    iopt := DefaultIteratorOptions    
    //iopt.AllVersions = true    // Uncomment this if you want to see all the keys in badger.
    
    it := txn.NewIterator(iopt)    
    defer it.Close()    
    
    var keys, keysWithEmptyValue int    
    for it.Rewind(); it.Valid(); it.Next() {    
        keys++    
        item := it.Item()    
        item.Value(func(val []byte) error {    
            if len(val) == 0 && item.meta&bitValuePointer > 0 {    
                keysWithEmptyValue++    
            }    
            return nil    
        })    
    }    
    fmt.Printf("keys: %d\n Keys with zero length value: %d\n", keys, keysWithEmptyValue)    
}    

@xiusin
Copy link

xiusin commented Apr 7, 2020

the same

 [ERRO] msg: runtime error: slice bounds out of range [4294967295:6231]  

 stack: goroutine 75 [running]:
        /home/xiusin/.bin/go/src/runtime/panic.go:967 +0x166
github.com/dgraph-io/badger/v2.(*valueLog).Read(0xc0002dedc8, 0x71c00000000, 0xc000002f1e, 0xc01da8d5c0, 0x7fe5274c1560, 0x0, 0xc018580684, 0xc, 0x5332c75, 0x17)
        /mnt/c/projects/pkg/mod/github.com/dgraph-io/badger/[email protected]/value.go:1512 +0x604
github.com/dgraph-io/badger/v2.(*Item).yieldItemValue(0xc00051fa20, 0xc00051fa20, 0x46e0fb, 0xc01d9f5120, 0x42, 0x0, 0xc018580684)
        /mnt/c/projects/pkg/mod/github.com/dgraph-io/badger/[email protected]/iterator.go:170 +0x11d
github.com/dgraph-io/badger/v2.(*Item).Value(0xc00051fa20, 0xc00047a730, 0x0, 0x0)
        /mnt/c/projects/pkg/mod/github.com/dgraph-io/badger/[email protected]/iterator.go:105 +0xd6
github.com/xiusin/xxxxxxx/cache/providers/badger.(*PineBadger).Get.func1(0xc01d8c3200, 0x12d0000, 0xc01d8c3200)

@jarifibrahim
Copy link
Contributor

This issue seems related to #1313. The bitValuePointer might be incorrectly set because of backup restore.

@cedricfung
Copy link
Author

cedricfung commented Apr 30, 2020 via email

@cedricfung
Copy link
Author

Any further steps to fix the existing data? Use the master branch to backup and restore? Any special params to use in the backup and restore?

@cedricfung
Copy link
Author

@jarifibrahim yes I'm using the default options.

@jarifibrahim
Copy link
Contributor

@cedricfung No. If you're using badger with default options, backup and restore on the latest master with #1313 should be enough.

@jarifibrahim
Copy link
Contributor

@cedricfung Are you still seeing crashes? If not, I'd like to mark this issue as fixed and close this issue.

@cedricfung
Copy link
Author

cedricfung commented Jun 3, 2020 via email

@jarifibrahim
Copy link
Contributor

Perfect. Thank you so much @cedricfung :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/crash This issue causes a panic or some other of exception that causes a crash. kind/maintenance Maintenance tasks, such as refactoring, with no impact in features. priority/P1 Serious issue that requires eventual attention (can wait a bit) status/accepted We accept to investigate or work on it.
Development

No branches or pull requests

4 participants