@@ -455,7 +455,7 @@ func (s *server) ReadRows(req *btpb.ReadRowsRequest, stream btpb.Bigtable_ReadRo
455
455
// Read all rows
456
456
tbl .rows .Ascend (addRow )
457
457
}
458
- gcRules := tbl .gcRules ()
458
+ gcRules := tbl .gcRulesNoLock ()
459
459
tbl .mu .RUnlock ()
460
460
461
461
rows := make ([]* row , 0 , len (rowSet ))
@@ -883,12 +883,15 @@ func (s *server) MutateRow(ctx context.Context, req *btpb.MutateRowRequest) (*bt
883
883
return nil , status .Errorf (codes .NotFound , "table %q not found" , req .TableName )
884
884
}
885
885
fs := tbl .columnFamilies ()
886
+
887
+ tbl .mu .Lock ()
888
+ defer tbl .mu .Unlock ()
886
889
r := tbl .mutableRow (string (req .RowKey ))
887
890
if err := applyMutations (tbl , r , req .Mutations , fs ); err != nil {
888
891
return nil , err
889
892
}
890
893
// JIT per-row GC
891
- r .gc (tbl .gcRules ())
894
+ r .gc (tbl .gcRulesNoLock ())
892
895
// JIT family deletion
893
896
for f , _ := range r .families {
894
897
if _ , ok := fs [f ]; ! ok {
@@ -920,7 +923,8 @@ func (s *server) MutateRows(req *btpb.MutateRowsRequest, stream btpb.Bigtable_Mu
920
923
res := & btpb.MutateRowsResponse {Entries : make ([]* btpb.MutateRowsResponse_Entry , len (req .Entries ))}
921
924
922
925
cfs := tbl .columnFamilies ()
923
-
926
+ tbl .mu .Lock ()
927
+ defer tbl .mu .Unlock ()
924
928
for i , entry := range req .Entries {
925
929
r := tbl .mutableRow (string (entry .RowKey ))
926
930
code , msg := int32 (codes .OK ), ""
@@ -932,7 +936,7 @@ func (s *server) MutateRows(req *btpb.MutateRowsRequest, stream btpb.Bigtable_Mu
932
936
Index : int64 (i ),
933
937
Status : & statpb.Status {Code : code , Message : msg },
934
938
}
935
- r .gc (tbl .gcRules ())
939
+ r .gc (tbl .gcRulesNoLock ())
936
940
// JIT family deletion; could be skipped if mutableRow doesn't return an existing row
937
941
for f , _ := range r .families {
938
942
if _ , ok := cfs [f ]; ! ok {
@@ -954,7 +958,8 @@ func (s *server) CheckAndMutateRow(ctx context.Context, req *btpb.CheckAndMutate
954
958
res := & btpb.CheckAndMutateRowResponse {}
955
959
956
960
cfs := tbl .columnFamilies ()
957
-
961
+ tbl .mu .Lock ()
962
+ defer tbl .mu .Unlock ()
958
963
r := tbl .mutableRow (string (req .RowKey ))
959
964
960
965
// Figure out which mutation to apply.
@@ -982,7 +987,7 @@ func (s *server) CheckAndMutateRow(ctx context.Context, req *btpb.CheckAndMutate
982
987
if err := applyMutations (tbl , r , muts , cfs ); err != nil {
983
988
return nil , err
984
989
}
985
- r .gc (tbl .gcRules ())
990
+ r .gc (tbl .gcRulesNoLock ())
986
991
// JIT family deletion; could be skipped if mutableRow doesn't return an existing row
987
992
for f , _ := range r .families {
988
993
if _ , ok := cfs [f ]; ! ok {
@@ -1119,7 +1124,8 @@ func (s *server) ReadModifyWriteRow(ctx context.Context, req *btpb.ReadModifyWri
1119
1124
}
1120
1125
1121
1126
cfs := tbl .columnFamilies ()
1122
-
1127
+ tbl .mu .Lock ()
1128
+ defer tbl .mu .Unlock ()
1123
1129
rowKey := string (req .RowKey )
1124
1130
r := tbl .mutableRow (rowKey )
1125
1131
resultRow := newRow (rowKey ) // copy of updated cells
@@ -1177,7 +1183,7 @@ func (s *server) ReadModifyWriteRow(ctx context.Context, req *btpb.ReadModifyWri
1177
1183
resultFamily .cellsByColumn (col ) // create the column
1178
1184
resultFamily .Cells [col ] = []cell {newCell } // overwrite the cells
1179
1185
}
1180
- r .gc (tbl .gcRules ())
1186
+ r .gc (tbl .gcRulesNoLock ())
1181
1187
// JIT family deletion; could be skipped if mutableRow doesn't return an existing row
1182
1188
for f , _ := range r .families {
1183
1189
if _ , ok := cfs [f ]; ! ok {
@@ -1318,7 +1324,10 @@ func (t *table) gcRules() map[string]*btapb.GcRule {
1318
1324
// This method doesn't add or remove rows, so we only need a read lock for the table.
1319
1325
t .mu .RLock ()
1320
1326
defer t .mu .RUnlock ()
1327
+ return t .gcRulesNoLock ()
1328
+ }
1321
1329
1330
+ func (t * table ) gcRulesNoLock () map [string ]* btapb.GcRule {
1322
1331
// Gather GC rules we'll apply.
1323
1332
rules := make (map [string ]* btapb.GcRule ) // keyed by "fam"
1324
1333
for fam , cf := range t .families {
0 commit comments