示例#1
0
// SetAsWriteContext sets all new writes will use this snapshot when writing. // TODO: Needs better testing
func (snapshot *ManagedSnapshot) SetAsWriteContext(snapshots ManagedSnapshots) error {
	sort.Sort(sort.Reverse(snapshots))
	snapContexts := make([]C.rados_snap_t, len(snapshots))
	for i, s := range snapshots {
		snapContexts[i] = C.rados_snap_t(s.Id)
	}
	seq := C.rados_snap_t(snapshot.Id)
	maxLen := C.int(len(snapshots))
	ret := C.rados_ioctx_selfmanaged_snap_set_write_ctx(snapshot.ioContext, seq, &snapContexts[0], maxLen)
	if err := toRadosError(ret); err != nil {
		err.Message = "Unable to set snapshot context for writing objects."
		return err
	}
	return nil
}
示例#2
0
// Remove will lazily remove the self managed snapshot.
func (snapshot *ManagedSnapshot) Remove() error {
	ret := C.rados_ioctx_selfmanaged_snap_remove(snapshot.ioContext, C.rados_snap_t(snapshot.Id))
	if err := toRadosError(ret); err != nil {
		err.Message = "Unable to remove snapshot."
		return err
	}
	return nil
}
示例#3
0
func (r *RadosIoCtx) SnapGetName(snapid RadosSnapId) (string, error) {
	var snapname [MAX_NAME_LEN]C.char
	cerr := C.rados_ioctx_snap_get_name(*r.ctx, C.rados_snap_t(snapid), &snapname[0], MAX_NAME_LEN)
	if cerr < 0 {
		return "", errors.New("get snap name failed")
	}

	return C.GoString(&snapname[0]), nil
}
示例#4
0
func (r *RadosIoCtx) SnapGetStamp(snapid RadosSnapId) (uint64, error) {
	var stamp C.time_t
	cerr := C.rados_ioctx_snap_get_stamp(*r.ctx, C.rados_snap_t(snapid), &stamp)
	if cerr < 0 {
		return 0, errors.New("get snap stamp failed")
	}

	return uint64(C.uint64_t(stamp)), nil
}
示例#5
0
// Rollback will rollback an object to this snapshot. TODO: Needs testing
func (snapshot *ManagedSnapshot) Rollback(objectId string) error {
	oid := C.CString(objectId)
	defer freeString(oid)
	ret := C.rados_ioctx_selfmanaged_snap_rollback(snapshot.ioContext, oid, C.rados_snap_t(snapshot.Id))
	if err := toRadosError(ret); err != nil {
		err.Message = fmt.Sprintf("Unable to rollback %s to managed pool %d.", objectId, snapshot.Id)
		return err
	}
	return nil
}
示例#6
0
// SnapshotTimestamp returns the timestamp the snapshot was created.
func (pool *Pool) SnapshotTimestamp(snapId SnapshotId) (time.Time, error) {
	id := C.rados_snap_t(snapId)
	var t C.time_t
	ret := C.rados_ioctx_snap_get_stamp(pool.context, id, &t)
	if err := toRadosError(ret); err != nil {
		err.Message = fmt.Sprintf("Unable to retrieve timestamp for snapshot id %d.", snapId)
		return time.Now(), err
	}
	goTime := time.Unix(int64(t), 0)
	return goTime, nil
}
示例#7
0
// ReverseLookupSnapshot returns the name of the given pool snapshot id.
func (pool *Pool) ReverseLookupSnapshot(snapId SnapshotId) (string, error) {
	id := C.rados_snap_t(snapId)
	bufLen := 8
	for {
		bufAddr := bufferAddress(bufLen)
		ret := C.rados_ioctx_snap_get_name(pool.context, id, bufAddr, C.int(bufLen))
		if int(ret) == -int(syscall.ERANGE) {
			bufLen *= 2
			continue
		}
		if ret < 0 {
			err := toRadosError(ret)
			err.Message = fmt.Sprintf("Unable to reverse lookup pool snapshot id %d.", snapId)
			return "", err
		}
		name := C.GoString(bufAddr)
		return name, nil
	}
}
示例#8
0
// UseSnapshot sets the pool context to use the snapshot for successive reads. Use NoSnapshot to not use snapshots when
// reading.
func (pool *Pool) UseSnapshot(snapId SnapshotId) {
	id := C.rados_snap_t(snapId)
	C.rados_ioctx_snap_set_read(pool.context, id)
}