HouzuoGuo/tiedot

How to read and delete all documents one by one?

Closed this issue · 2 comments

I need to read a document and delete it immediately with forEach function.

feeds.ForEachDoc(func(id int, docContent []byte) (willMoveOn bool) {
			fmt.Println("Document", id, "is", string(docContent))
			feeds.Delete(id)
			return true  // move on to the next document OR
			return false // do not move on to the next document
		})

the above code gives me this error

fatal error: all goroutines are asleep - deadlock!
goroutine 1 [semacquire]:
sync.runtime_Semacquire(0xc0420527a8)
C:/Go/src/runtime/sema.go:47 +0x37
sync.(*RWMutex).Lock(0xc0420527a0)
C:/Go/src/sync/rwmutex.go:91 +0x9f
github.com/HouzuoGuo/tiedot/db.(*Col).Delete(0xc04206c0f0, 0x2a225da552e87ac, 0x4, 0x39)
E:/Go_Programs/path/src/github.com/HouzuoGuo/tiedot/db/doc.go:315 +0xaf
main.embeddedExample.func2.1(0x2a225da552e87ac, 0xc042033ef0, 0x2a, 0x2a, 0x2a)
F:/GoWorkspace/tiedotDB/dbReader.go:182 +0x209
github.com/HouzuoGuo/tiedot/data.(*Partition).ForEachDoc(0xc04207e120, 0x0, 0x10f, 0xc04241dea0, 0x16)
E:/Go_Programs/path/src/github.com/HouzuoGuo/tiedot/data/partition.go:131 +0x13a
github.com/HouzuoGuo/tiedot/db.(*Col).forEachDoc(0xc04206c0f0, 0xc04241dea0, 0xc04202be01)
E:/Go_Programs/path/src/github.com/HouzuoGuo/tiedot/db/col.go:119 +0x160
github.com/HouzuoGuo/tiedot/db.(*Col).ForEachDoc(0xc04206c0f0, 0xc04241dea0)
E:/Go_Programs/path/src/github.com/HouzuoGuo/tiedot/db/col.go:130 +0x41
main.embeddedExample.func2(0xc04206c0f0)
F:/GoWorkspace/tiedotDB/dbReader.go:187 +0x60
main.embeddedExample()
F:/GoWorkspace/tiedotDB/dbReader.go:188 +0x1e5
main.main()
F:/GoWorkspace/tiedotDB/dbReader.go:195 +0x1b

goroutine 4 [chan receive]:
main.embeddedExample.func1(0xc04202eba0, 0xc04206c0f0)
F:/GoWorkspace/tiedotDB/dbReader.go:169 +0x86
created by main.embeddedExample
F:/GoWorkspace/tiedotDB/dbReader.go:177 +0x1d7
exit status 2

How to solve this?

Hello! Please avoid iteration and removal of documents at the same time. Save the IDs to a slice outside of the function, and then iterate over the IDs to remove documents.