Skip to content

Get after a Merge will throw a segmentation violation #1

@mijia

Description

@mijia

Hi,

I am trying to wrap rocksdb inside my Go code and your wrapper is a great library. But I got a segmentation violation fatal error when "Get" after a single "Merge" call with a fresh database.

The code to reproduce this is,

package main

import (
    rocks "github.com/tecbot/gorocksdb"
    "fmt"
    "runtime"
    "sync"
)

type Handler struct {}

func (h *Handler) FullMerge(key, existingValue []byte, operands [][]byte) ([]byte, bool) {
    fmt.Println("FullMerge called.")
    for _, operand := range operands {
        existingValue = append(existingValue, operand...)
    }
    return existingValue, true
}

func (h *Handler) PartialMerge(key, leftOperand, rightOperand []byte) ([]byte, bool) {
    return nil, false
}

func (h *Handler) Name() string {
    return "GoRockdisMergeOperator"
}


func main() {
    runtime.GOMAXPROCS(runtime.NumCPU())

    opts := rocks.NewDefaultOptions()
    opts.SetCreateIfMissing(true)
    opts.SetMergeOperator(rocks.NewMergeOperator(&Handler{}))

    db, err := rocks.OpenDb(opts, "/opt/tmp/rocksdb")
    if err != nil {
        panic(err)
    }

    var wg sync.WaitGroup
    wg.Add(1)
    go func() {
        ro := rocks.NewDefaultReadOptions()
        wo := rocks.NewDefaultWriteOptions()

        err = db.Merge(wo, []byte("test"), []byte("hello"))
        if err != nil {
            panic(err)
        }

        data, err := db.Get(ro, []byte("test"))
        if err != nil {
            panic(err)
        }
        fmt.Println(string(data.Data()))
        wg.Done()
    }()

    wg.Wait()
}

The error is,

SIGSEGV: segmentation violation
PC=0x420f339
signal arrived during cgo execution

runtime.cgocall(0x40011b0, 0x4491e28)
    /usr/local/Cellar/go/1.2/libexec/src/pkg/runtime/cgocall.c:149 +0x11b fp=0x4491e10
github.com/tecbot/gorocksdb._Cfunc_rocksdb_get(0x4513e50, 0x4505350, 0xc210000068, 0x4, 0xc210000078, ...)
    github.com/tecbot/gorocksdb/_obj/_cgo_defun.c:318 +0x36 fp=0x4491e28
github.com/tecbot/gorocksdb.(*DB).Get(0xc21004d000, 0xc210000040, 0xc210000068, 0x4, 0x4, ...)
    /Users/mijia/Projects/sandbox/gocode/src/github.com/tecbot/gorocksdb/db.go:55 +0xf0 fp=0x4491ea8
main.func·001()
    /Users/mijia/Projects/sandbox/gocode/src/github.com/mijia/gorockdis/test/merge_fail.go:52 +0x266 fp=0x4491fa0
...

I am using Mac OS 10.9.1, any clue for this?
Thank you very much.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions