Esempio n. 1
0
//
// Retrieve entry from commit log
//
func (r *CommitLog) Get(txid common.Txnid) (common.OpCode, string, []byte, error) {

	k := createLogKey(txid)
	data, err := r.repo.Get(COMMIT_LOG, k)
	if err != nil {
		return common.OPCODE_INVALID, "", nil, err
	}

	entry, err := unmarshall(data)
	if err != nil {
		return common.OPCODE_INVALID, "", nil, err
	}
	return common.GetOpCodeFromInt(entry.GetOpCode()), entry.GetKey(), entry.GetContent(), nil
}
Esempio n. 2
0
//
// Retrieve entry from commit log
//
func (r *TransientCommitLog) Get(txid common.Txnid) (common.OpCode, string, []byte, error) {

	msg, ok := r.logs[txid]
	if !ok || msg == nil {
		err := common.NewError(common.REPO_ERROR, fmt.Sprintf("LogEntry for txid %d does not exist in commit log", txid))
		return common.OPCODE_INVALID, "", nil, err
	}

	// msg is a protobuf object. Directly pointing slices/strings into a struct
	// may cause problems for cgo calls
	key := string([]byte(msg.GetKey()))
	content := []byte(string(msg.GetContent()))
	return common.GetOpCodeFromInt(msg.GetOpCode()), key, content, nil
}
Esempio n. 3
0
// Get value from iterator
func (i *LogIterator) Next() (txnid common.Txnid, op common.OpCode, key string, content []byte, err error) {

	// TODO: Check if fdb and iterator is closed
	key, content, err = i.iter.Next()
	if err != nil {
		return 0, common.OPCODE_INVALID, "", nil, err
	}

	// Since actual data is stored in the same repository, make sure
	// we don't read them.
	log.Current.Debugf("CommitLog.Next() : Iterator read key %s", key)

	entry, err := unmarshall(content)
	if err != nil {
		return 0, common.OPCODE_INVALID, "", nil, err
	}

	return common.Txnid(entry.GetTxnid()),
		common.GetOpCodeFromInt(entry.GetOpCode()),
		entry.GetKey(), entry.GetContent(), nil
}