Exemplo n.º 1
0
func (log *Log) Trim(position uint64) error {
	ret := C.zlog_trim(C.zlog_log_t(log.log), C.uint64_t(position))
	if ret == 0 {
		return nil
	} else {
		return ZlogError(int(ret))
	}
}
Exemplo n.º 2
0
func (log *Log) CheckTailBatch(positions []uint64) error {
	ret := C.zlog_checktail_batch(C.zlog_log_t(log.log),
		(*C.uint64_t)(unsafe.Pointer(&positions[0])),
		(C.size_t)(len(positions)))
	if ret == 0 {
		return nil
	} else {
		return ZlogError(int(ret))
	}
}
Exemplo n.º 3
0
func (log *Log) OpenStream(id uint64) (*Stream, error) {
	stream := &Stream{}

	ret := C.zlog_stream_open(C.zlog_log_t(log.log), C.uint64_t(id),
		&stream.stream)

	if ret == 0 {
		return stream, nil
	} else {
		return nil, ZlogError(int(ret))
	}
}
Exemplo n.º 4
0
func (log *Log) Read(position uint64, data []byte) (int, error) {
	if len(data) == 0 {
		return 0, nil
	}

	ret := C.zlog_read(C.zlog_log_t(log.log), C.uint64_t(position),
		unsafe.Pointer(&data[0]), (C.size_t)(len(data)))

	if ret >= 0 {
		return int(ret), nil
	} else {
		return 0, ZlogError(int(ret))
	}
}
Exemplo n.º 5
0
func (log *Log) Append(data []byte) (uint64, error) {
	var c_position C.uint64_t

	ret := C.zlog_append(C.zlog_log_t(log.log),
		unsafe.Pointer(&data[0]),
		(C.size_t)(len(data)),
		&c_position)

	if ret == 0 {
		return uint64(c_position), nil
	} else {
		return 0, ZlogError(int(ret))
	}
}
Exemplo n.º 6
0
func (log *Log) StreamMembership(position uint64) ([]uint64, error) {
	stream_ids := make([]uint64, 1)
	for {
		ret := C.zlog_stream_membership(C.zlog_log_t(log.log),
			(*C.uint64_t)(&stream_ids[0]), (C.size_t)(len(stream_ids)),
			C.uint64_t(position))
		if ret < 0 {
			return nil, ZlogError(int(ret))
		} else if int(ret) <= len(stream_ids) {
			return stream_ids[:ret], nil
		} else {
			stream_ids = make([]uint64, ret)
		}
	}
}
Exemplo n.º 7
0
func (log *Log) CheckTail(next bool) (uint64, error) {
	var c_position C.uint64_t
	var c_next C.int
	if next {
		c_next = 1
	} else {
		c_next = 0
	}
	ret := C.zlog_checktail(C.zlog_log_t(log.log), &c_position, c_next)
	if ret == 0 {
		return uint64(c_position), nil
	} else {
		return 0, ZlogError(int(ret))
	}
}
Exemplo n.º 8
0
func (log *Log) MultiAppend(data []byte, stream_ids []uint64) (uint64, error) {
	var c_position C.uint64_t
	var c_stream_ids *C.uint64_t = nil
	if len(stream_ids) > 0 {
		c_stream_ids = (*C.uint64_t)(unsafe.Pointer(&stream_ids[0]))
	}
	ret := C.zlog_multiappend(C.zlog_log_t(log.log),
		unsafe.Pointer(&data[0]),
		(C.size_t)(len(data)),
		c_stream_ids,
		(C.size_t)(len(stream_ids)),
		&c_position)
	if ret == 0 {
		return uint64(c_position), nil
	} else {
		return 0, ZlogError(int(ret))
	}
}
Exemplo n.º 9
0
func (log *Log) Destroy() {
	C.zlog_destroy(C.zlog_log_t(log.log))
}