Exemplo n.º 1
0
    def WalkBuffer(self):
        self.mutations = list()
        keys = set()
        for k, v in self.membuf.iteritems():
            mutation = kvrpcpb.Mutation()
            mutation.key = k
            # Insert => Insert
            if k in self.insertKeys:
                mutation.op = kvrpcpb.Insert
                if v:
                    mutation.value = v
            # Set => Update/Delete
            else:
                if v:
                    mutation.op = kvrpcpb.Put
                    mutation.value = v
                else:
                    mutation.op = kvrpcpb.Del
                    mutation.key = k
            self.mutations.append(mutation)
            keys.add(k)

        for k in self.lockKeys:
            if k in keys:
                continue
            mutation = kvrpcpb.Mutation(op=kvrpcpb.Lock, key=k)
            self.mutations.append(mutation)
            keys.add(k)
        if len(self.mutations) > 0:
            self.primary = EncodePrimary(self.col, self.mutations[0].key)
Exemplo n.º 2
0
    def test_WalkBuffer(self):
        def setV10():
            self.mustSetOK('A', 'A10')
            self.mustSetOK('C', None)
            self.mustInsertOK('E', 'E10')

        setV10()
        mutations = [
            kvrpcpb.Mutation(op=kvrpcpb.Put, key='A', value='A10'),
            kvrpcpb.Mutation(op=kvrpcpb.Del, key='C', value=None),
            kvrpcpb.Mutation(op=kvrpcpb.Insert, key='E', value='E10'),
        ]

        self.mustWalkBufferOK(mutations)

        def deleteV10():
            self.mustDeleteOK('E')

        deleteV10()
        mutations = [
            kvrpcpb.Mutation(op=kvrpcpb.Put, key='A', value='A10'),
            kvrpcpb.Mutation(op=kvrpcpb.Del, key='C', value=None),
            kvrpcpb.Mutation(op=kvrpcpb.Del, key='E', value=None),
        ]
        self.mustWalkBufferOK(mutations)

        def lockV10():
            self.mustLockkeyOK('A')
            self.mustLockkeyOK('G')

        lockV10()
        mutations = [
            kvrpcpb.Mutation(op=kvrpcpb.Put, key='A', value='A10'),
            kvrpcpb.Mutation(op=kvrpcpb.Del, key='C', value=None),
            kvrpcpb.Mutation(op=kvrpcpb.Del, key='E', value=None),
            kvrpcpb.Mutation(op=kvrpcpb.Lock, key='G', value=None),
        ]
        self.mustWalkBufferOK(mutations)

        logger.debug('primary key is: %s' % self.cs.primary)
Exemplo n.º 3
0
def putMutations(*kvpairs):
    '''
    @type kvpairs:  list(str)
    @rtype: list(kvrpcpb.Mutation)
    '''
    mutations = list()
    for i in range(len(kvpairs))[::2]:
        mutation = kvrpcpb.Mutation()
        mutation.op = kvrpcpb.Put
        mutation.key = kvpairs[i]
        mutation.value = kvpairs[i + 1]
        mutations.append(mutation)
    return mutations
Exemplo n.º 4
0
    def mustDeleteOK(self, key, startTS, commitTS):
        mutations = list()
        mutation = kvrpcpb.Mutation()
        mutation.op = kvrpcpb.Del
        mutation.key = key
        mutations.append(mutation)

        errs = self.store.Prewrite(mutations, key, startTS, 0)
        for err in errs:
            self.assertEqual(err, None)

        err = self.store.Commit([key], startTS, commitTS)
        self.assertEqual(err, None)
Exemplo n.º 5
0
    def test_GetWithLock(self):
        key = "key"
        value = "value"
        self.mustPutOK(key, value, 5, 10)
        mutations = list()
        mutation = kvrpcpb.Mutation()
        mutation.op = kvrpcpb.Lock
        mutation.key = key
        mutations.append(mutation)

        # test with lock's type is lock
        self.mustPrewriteOK(mutations, key, 20)
        self.mustGetOK(key, 25, value)
        self.mustCommitOK([key], 20, 30)

        # test get with lock's max ts and primary key
        self.mustPrewriteOK(putMutations(key, "value2", "key2", "v5"), key, 40)
        self.mustGetErr(key, 41)
        self.mustGetErr("key2", lockVer)