Skip to content

Commit 016fc6a

Browse files
xelavopelkKlepov Alex
andauthored
fix sequence issues (#1587)
Co-authored-by: Klepov Alex <aklepov@rutube.ru>
1 parent 7f7f217 commit 016fc6a

File tree

4 files changed

+77
-3
lines changed

4 files changed

+77
-3
lines changed

qdb/etcdqdb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,7 @@ func (q *EtcdQDB) AlterSequenceDetachRelation(ctx context.Context, relName *rfqn
18481848
Str("relation", relName.RelationName).
18491849
Msg("etcdqdb: detach relation from sequence")
18501850

1851-
resp, err := q.cli.Delete(ctx, relationSequenceMappingNodePath(relName.RelationName))
1851+
resp, err := q.cli.Delete(ctx, relationSequenceMappingNodePath(relName.RelationName), clientv3.WithPrefix())
18521852
spqrlog.Zero.Debug().
18531853
Interface("response", resp).
18541854
Msg("etcdqdb: detach relation from sequence")
@@ -1861,7 +1861,7 @@ func (q *EtcdQDB) GetRelationSequence(ctx context.Context, relName *rfqn.Relatio
18611861
Msg("etcdqdb: get column sequence")
18621862

18631863
key := relationSequenceMappingNodePath(relName.RelationName)
1864-
resp, err := q.cli.Get(ctx, key)
1864+
resp, err := q.cli.Get(ctx, key, clientv3.WithPrefix())
18651865
if err != nil {
18661866
return nil, err
18671867
}

qdb/memqdb.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,8 @@ func (q *MemQDB) DropSequence(ctx context.Context, seqName string, force bool) e
11451145
return nil
11461146
}
11471147

1148-
return ExecuteCommands(q.DumpState, NewDeleteCommand(q.Sequences, seqName))
1148+
return ExecuteCommands(q.DumpState, NewDeleteCommand(q.Sequences, seqName),
1149+
NewDeleteCommand(q.SequenceToValues, seqName))
11491150
}
11501151

11511152
func (q *MemQDB) GetRelationSequence(_ context.Context, relName *rfqn.RelationFQN) (map[string]string, error) {

qdb/memqdb_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,34 @@ func TestMemQDB_GetAbsentDistribution(t *testing.T) {
174174
assert.Error(err)
175175
}
176176

177+
func TestDropReferenceRelation(t *testing.T) {
178+
179+
assert := assert.New(t)
180+
181+
memqdb, err := qdb.RestoreQDB(MemQDBPath)
182+
assert.NoError(err)
183+
184+
ctx := context.TODO()
185+
referenceRelation := &qdb.ReferenceRelation{
186+
TableName: "test2",
187+
SchemaVersion: 1,
188+
ColumnSequenceMapping: map[string]string{"id": "test2_id"},
189+
ShardIds: []string{"sh1", "sh2"},
190+
}
191+
err = memqdb.CreateReferenceRelation(ctx, referenceRelation)
192+
assert.NoError(err)
193+
err = memqdb.DropReferenceRelation(ctx, &rfqn.RelationFQN{RelationName: "test2"})
194+
assert.NoError(err)
195+
_, err = memqdb.GetReferenceRelation(ctx, &rfqn.RelationFQN{RelationName: "test2"})
196+
assert.Error(err)
197+
assert.Equal(0, len(memqdb.Sequences))
198+
assert.Equal(0, len(memqdb.ColumnSequence))
199+
assert.Equal(0, len(memqdb.SequenceToValues))
200+
assert.Equal(0, len(memqdb.ReferenceRelations))
201+
202+
assert.NoError(memqdb.DropKeyRange(ctx, "nonexistentKeyRange"))
203+
}
204+
177205
func TestKeyRanges(t *testing.T) {
178206

179207
assert := assert.New(t)

test/feature/features/sequence.feature

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,48 @@ Feature: Sequence test
100100
}
101101
]
102102
"""
103+
104+
Scenario: Remove sequence
105+
#
106+
# Make host "coordinator" take control
107+
#
108+
Given cluster environment is
109+
"""
110+
ROUTER_CONFIG=/spqr/test/feature/conf/router_cluster.yaml
111+
"""
112+
Given cluster is up and running
113+
And host "coordinator2" is stopped
114+
And host "coordinator2" is started
115+
116+
117+
When I run SQL on host "coordinator"
118+
"""
119+
CREATE REFERENCE TABLE t AUTO INCREMENT id;
120+
"""
121+
Then command return code should be "0"
122+
123+
When I run SQL on host "coordinator"
124+
"""
125+
SHOW sequences;
126+
"""
127+
Then command return code should be "0"
128+
And SQL result should match json_exactly
129+
"""
130+
[
131+
{
132+
"name": "t_id",
133+
"value": "0"
134+
}
135+
]
136+
"""
137+
138+
When I run SQL on host "coordinator"
139+
"""
140+
DROP REFERENCE RELATION t;
141+
SHOW sequences;
142+
"""
143+
Then command return code should be "0"
144+
And SQL result should match json_exactly
145+
"""
146+
[]
147+
"""

0 commit comments

Comments
 (0)