Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bigtable): emulator crashes in SampleRowKeys #4455

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions bigtable/bttest/inmem.go
Expand Up @@ -1124,6 +1124,8 @@ func (s *server) SampleRowKeys(req *btpb.SampleRowKeysRequest, stream btpb.Bigta
i := 0
tbl.rows.Ascend(func(it btree.Item) bool {
row := it.(*row)
row.mu.Lock()
defer row.mu.Unlock()
if i == tbl.rows.Len()-1 || rand.Int31n(100) == 0 {
resp := &btpb.SampleRowKeysResponse{
RowKey: []byte(row.key),
Expand Down
76 changes: 65 additions & 11 deletions bigtable/bttest/inmem_test.go
Expand Up @@ -275,7 +275,9 @@ func TestSampleRowKeys(t *testing.T) {
}
}

func TestTableRowsConcurrent(t *testing.T) {
type AntagonistFunction func(s *server, attempts int, tblName string, finished chan (bool))

func SampleRowKeysConcurrentTest(t *testing.T, antagonist AntagonistFunction) {
s := &server{
tables: make(map[string]*table),
}
Expand Down Expand Up @@ -324,25 +326,77 @@ func TestTableRowsConcurrent(t *testing.T) {
}
finished <- true
}()
go func() {
go antagonist(s, attempts, tbl.Name, finished)
for i := 0; i < 2; i++ {
select {
case <-finished:
case <-time.After(2 * time.Second):
t.Fatalf("Timeout waiting for task %d\n", i)
}
}
}

func TestSampleRowKeysVsDropRowRange(t *testing.T) {
SampleRowKeysConcurrentTest(t, func(s *server, attempts int, tblName string, finished chan (bool)) {
ctx := context.Background()
for i := 0; i < attempts; i++ {
req := &btapb.DropRowRangeRequest{
Name: tbl.Name,
Name: tblName,
Target: &btapb.DropRowRangeRequest_DeleteAllDataFromTable{DeleteAllDataFromTable: true},
}
if _, err = s.DropRowRange(ctx, req); err != nil {
if _, err := s.DropRowRange(ctx, req); err != nil {
t.Fatalf("Dropping all rows: %v", err)
}
}
finished <- true
}()
for i := 0; i < 2; i++ {
select {
case <-finished:
case <-time.After(2 * time.Second):
t.Fatalf("Timeout waiting for task %d\n", i)
})
}

func TestSampleRowKeysVsModifyColumnFamilies(t *testing.T) {
SampleRowKeysConcurrentTest(t, func(s *server, attempts int, tblName string, finished chan (bool)) {
ctx := context.Background()
for i := 0; i < attempts; i++ {
req := &btapb.ModifyColumnFamiliesRequest{
Name: tblName,
Modifications: []*btapb.ModifyColumnFamiliesRequest_Modification{{
Id: "cf2",
Mod: &btapb.ModifyColumnFamiliesRequest_Modification_Create{Create: &btapb.ColumnFamily{}},
}},
}
if _, err := s.ModifyColumnFamilies(ctx, req); err != nil {
t.Fatalf("Creating column family cf2: %v", err)
}
rowCount := 100
for i := 0; i < rowCount; i++ {
req := &btpb.MutateRowRequest{
TableName: tblName,
RowKey: []byte("row-" + strconv.Itoa(i)),
Mutations: []*btpb.Mutation{{
Mutation: &btpb.Mutation_SetCell_{SetCell: &btpb.Mutation_SetCell{
FamilyName: "cf2",
ColumnQualifier: []byte("col"),
TimestampMicros: 1000,
Value: []byte("value"),
}},
}},
}
if _, err := s.MutateRow(ctx, req); err != nil {
t.Fatalf("Populating table: %v", err)
}
}
req = &btapb.ModifyColumnFamiliesRequest{
Name: tblName,
Modifications: []*btapb.ModifyColumnFamiliesRequest_Modification{{
Id: "cf2",
Mod: &btapb.ModifyColumnFamiliesRequest_Modification_Drop{Drop: true},
}},
}
if _, err := s.ModifyColumnFamilies(ctx, req); err != nil {
t.Fatalf("Dropping column family cf2: %v", err)
}
}
}
finished <- true
})
}

func TestModifyColumnFamilies(t *testing.T) {
Expand Down