rados: add support for retrieving the alignment (stripe size) for EC pools

Add support for getting the alignment (stripe size) in bytes for pools that require/support it.
Fixes #739

This commit adds two new API calls to IOContext, one to know if the pool requires alignment and
the second one to get the stripe size in bytes:

 RequiresAlignment() (bool, error)
 Alignment() (uint64, error)

Signed-off-by: Daniel M. Lambea <dmlambea@tenerife.es>
This commit is contained in:
Daniel M. Lambea 2022-07-20 12:25:04 +01:00 committed by mergify[bot]
parent fdd9853f0f
commit f06baa43e5
4 changed files with 84 additions and 0 deletions

View File

@ -0,0 +1,27 @@
//go:build ceph_preview
// +build ceph_preview
package rados
// #cgo LDFLAGS: -lrados
// #include <rados/librados.h>
// #include <stdlib.h>
//
import "C"
// Alignment returns the required stripe size in bytes for pools supporting/requiring it, or an error if unsuccessful.
// For an EC pool, a buffer size multiple of its stripe size is required to call Append. To know if the pool requires
// alignment or not, use RequiresAlignment.
//
// Implements:
// int rados_ioctx_pool_required_alignment2(rados_ioctx_t io, uint64_t *alignment)
func (ioctx *IOContext) Alignment() (uint64, error) {
var alignSizeBytes C.uint64_t
ret := C.rados_ioctx_pool_required_alignment2(
ioctx.ioctx,
&alignSizeBytes)
if ret != 0 {
return 0, getError(ret)
}
return uint64(alignSizeBytes), nil
}

View File

@ -0,0 +1,15 @@
//go:build ceph_preview
// +build ceph_preview
package rados
import (
"github.com/stretchr/testify/assert"
)
func (suite *RadosTestSuite) TestAlignment() {
suite.SetupConnection()
_, err := suite.ioctx.Alignment()
assert.NoError(suite.T(), err)
}

View File

@ -0,0 +1,27 @@
//go:build ceph_preview
// +build ceph_preview
package rados
// #cgo LDFLAGS: -lrados
// #include <rados/librados.h>
// #include <stdlib.h>
//
import "C"
// RequiresAlignment returns true if the pool supports/requires alignment or an error if not successful.
// For an EC pool, a buffer size multiple of its stripe size is required to call Append. See
// Alignment to know how to get the stripe size for pools requiring it.
//
// Implements:
// int rados_ioctx_pool_requires_alignment2(rados_ioctx_t io, int *req)
func (ioctx *IOContext) RequiresAlignment() (bool, error) {
var alignRequired C.int
ret := C.rados_ioctx_pool_requires_alignment2(
ioctx.ioctx,
&alignRequired)
if ret != 0 {
return false, getError(ret)
}
return (alignRequired != 0), nil
}

View File

@ -0,0 +1,15 @@
//go:build ceph_preview
// +build ceph_preview
package rados
import (
"github.com/stretchr/testify/assert"
)
func (suite *RadosTestSuite) TestRequiresAlignment() {
suite.SetupConnection()
_, err := suite.ioctx.RequiresAlignment()
assert.NoError(suite.T(), err)
}