Пример #1
0
func getTestKV(tableId uint8, rowKey, colKey, value []byte, score int64, cas uint32) proto.KeyValue {
	var kv proto.KeyValue
	kv.TableId = tableId
	kv.RowKey = rowKey
	kv.ColKey = colKey
	kv.SetValue(value)
	kv.SetScore(score)
	kv.SetCas(cas)
	return kv
}
Пример #2
0
func (tbl *Table) getKV(rOpt *ReadOptions, zop bool, dbId uint8,
	kv *proto.KeyValue, wa *WriteAccess) error {
	kv.CtrlFlag &^= 0xFF // Clear all ctrl flags

	if kv.Cas > 0 && !wa.CheckKey(dbId, kv.TableId, kv.RowKey) {
		kv.SetErrCode(table.EcSlaveCas)
		return nil
	}

	var rawColSpace uint8 = proto.ColSpaceDefault
	if zop {
		rawColSpace = proto.ColSpaceScore2
	}
	var rawKey = getRawKey(dbId, kv.TableId, rawColSpace, kv.RowKey, kv.ColKey)

	var err error
	kv.Value, err = tbl.db.Get(rOpt, rawKey)
	if err != nil {
		kv.SetErrCode(table.EcReadFail)
		return err
	} else if kv.Value == nil {
		// Key not exist
		kv.SetErrCode(table.EcNotExist)
	} else {
		// Key exists
		kv.Value, kv.Score = parseRawValue(kv.Value)
		if len(kv.Value) > 0 {
			kv.CtrlFlag |= proto.CtrlValue
		}
		if kv.Score != 0 {
			kv.CtrlFlag |= proto.CtrlScore
		}
	}

	if kv.Cas > 1 {
		var rawKey = getRawKey(dbId, kv.TableId, rawColSpace, kv.RowKey, kv.ColKey)

		var lck = tbl.tl.GetLock(rawKey)
		lck.Lock()
		kv.SetCas(lck.NewCas(rawKey))
		lck.Unlock()
	}

	return nil
}