2022-01-26 15:08:53 +00:00
|
|
|
//go:build ceph_preview
|
|
|
|
// +build ceph_preview
|
|
|
|
|
|
|
|
package rados
|
|
|
|
|
|
|
|
// #cgo LDFLAGS: -lrados
|
|
|
|
// #include <rados/librados.h>
|
|
|
|
// #include <stdlib.h>
|
|
|
|
//
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
2022-02-10 19:17:43 +00:00
|
|
|
|
|
|
|
"github.com/ceph/go-ceph/internal/cutil"
|
2022-01-26 15:08:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ReadOpOmapGetValsByKeysStep holds the result of the
|
|
|
|
// GetOmapValuesByKeys read operation.
|
|
|
|
// Result is valid only after Operate() was called.
|
|
|
|
type ReadOpOmapGetValsByKeysStep struct {
|
|
|
|
// C arguments
|
|
|
|
|
|
|
|
iter C.rados_omap_iter_t
|
|
|
|
prval *C.int
|
|
|
|
|
|
|
|
// Internal state
|
|
|
|
|
|
|
|
// canIterate is only set after the operation is performed and is
|
|
|
|
// intended to prevent premature fetching of data.
|
|
|
|
canIterate bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func newReadOpOmapGetValsByKeysStep() *ReadOpOmapGetValsByKeysStep {
|
|
|
|
s := &ReadOpOmapGetValsByKeysStep{
|
|
|
|
prval: (*C.int)(C.malloc(C.sizeof_int)),
|
|
|
|
}
|
|
|
|
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ReadOpOmapGetValsByKeysStep) free() {
|
|
|
|
s.canIterate = false
|
|
|
|
C.rados_omap_get_end(s.iter)
|
|
|
|
|
|
|
|
C.free(unsafe.Pointer(s.prval))
|
|
|
|
s.prval = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ReadOpOmapGetValsByKeysStep) update() error {
|
|
|
|
err := getError(*s.prval)
|
|
|
|
s.canIterate = (err == nil)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next gets the next omap key/value pair referenced by
|
|
|
|
// ReadOpOmapGetValsByKeysStep's internal iterator.
|
|
|
|
// If there are no more elements to retrieve, (nil, nil) is returned.
|
|
|
|
// May be called only after Operate() finished.
|
|
|
|
// PREVIEW
|
|
|
|
func (s *ReadOpOmapGetValsByKeysStep) Next() (*OmapKeyValue, error) {
|
|
|
|
if !s.canIterate {
|
|
|
|
return nil, ErrOperationIncomplete
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
cKey *C.char
|
|
|
|
cVal *C.char
|
2022-02-10 18:54:10 +00:00
|
|
|
cKeyLen C.size_t
|
2022-01-26 15:08:53 +00:00
|
|
|
cValLen C.size_t
|
|
|
|
)
|
|
|
|
|
2022-02-10 18:54:10 +00:00
|
|
|
ret := C.rados_omap_get_next2(s.iter, &cKey, &cVal, &cKeyLen, &cValLen)
|
2022-01-26 15:08:53 +00:00
|
|
|
if ret != 0 {
|
|
|
|
return nil, getError(ret)
|
|
|
|
}
|
|
|
|
|
|
|
|
if cKey == nil {
|
|
|
|
// Iterator has reached the end of the list.
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &OmapKeyValue{
|
2022-02-10 18:54:10 +00:00
|
|
|
Key: string(C.GoBytes(unsafe.Pointer(cKey), C.int(cKeyLen))),
|
2022-01-26 15:08:53 +00:00
|
|
|
Value: C.GoBytes(unsafe.Pointer(cVal), C.int(cValLen)),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetOmapValuesByKeys starts iterating over specific key/value pairs.
|
|
|
|
// PREVIEW
|
|
|
|
//
|
|
|
|
// Implements:
|
2022-02-10 19:17:43 +00:00
|
|
|
// void rados_read_op_omap_get_vals_by_keys2(rados_read_op_t read_op,
|
|
|
|
// char const * const * keys,
|
|
|
|
// size_t num_keys,
|
|
|
|
// const size_t * key_lens,
|
|
|
|
// rados_omap_iter_t * iter,
|
|
|
|
// int * prval)
|
2022-01-26 15:08:53 +00:00
|
|
|
func (r *ReadOp) GetOmapValuesByKeys(keys []string) *ReadOpOmapGetValsByKeysStep {
|
|
|
|
s := newReadOpOmapGetValsByKeysStep()
|
|
|
|
r.steps = append(r.steps, s)
|
|
|
|
|
2022-02-10 19:17:43 +00:00
|
|
|
cKeys := cutil.NewBufferGroupStrings(keys)
|
|
|
|
defer cKeys.Free()
|
2022-01-26 15:08:53 +00:00
|
|
|
|
2022-02-10 19:17:43 +00:00
|
|
|
C.rados_read_op_omap_get_vals_by_keys2(
|
2022-01-26 15:08:53 +00:00
|
|
|
r.op,
|
2022-02-10 19:17:43 +00:00
|
|
|
(**C.char)(cKeys.BuffersPtr()),
|
2022-01-26 15:08:53 +00:00
|
|
|
C.size_t(len(keys)),
|
2022-02-10 19:17:43 +00:00
|
|
|
(*C.size_t)(cKeys.LengthsPtr()),
|
2022-01-26 15:08:53 +00:00
|
|
|
&s.iter,
|
|
|
|
s.prval,
|
|
|
|
)
|
|
|
|
|
|
|
|
return s
|
|
|
|
}
|