Browse code

libnetwork/bit{seq,map}: delete CheckConsistency()

That method was only referenced by ipam.Allocator, but as it no longer
stores any state persistently there is no possibility for it to load an
inconsistent bit-sequence from Docker 1.9.x.

Signed-off-by: Cory Snider <csnider@mirantis.com>

Cory Snider authored on 2023/01/25 08:54:05
Showing 4 changed files
... ...
@@ -231,21 +231,6 @@ func (h *Bitmap) IsSet(ordinal uint64) bool {
231 231
 	return err != nil
232 232
 }
233 233
 
234
-// CheckConsistency checks if the bit sequence is in an inconsistent state and attempts to fix it.
235
-// It looks for a corruption signature that may happen in docker 1.9.0 and 1.9.1.
236
-func (h *Bitmap) CheckConsistency() bool {
237
-	corrupted := false
238
-	for p, c := h.head, h.head.next; c != nil; c = c.next {
239
-		if c.count == 0 {
240
-			corrupted = true
241
-			p.next = c.next
242
-			continue // keep same p
243
-		}
244
-		p = c
245
-	}
246
-	return corrupted
247
-}
248
-
249 234
 // set/reset the bit
250 235
 func (h *Bitmap) set(ordinal, start, end uint64, any bool, release bool, serial bool) (uint64, error) {
251 236
 	var (
... ...
@@ -963,136 +963,6 @@ func TestAllocateRandomDeallocateSerialize(t *testing.T) {
963 963
 	}
964 964
 }
965 965
 
966
-func TestIsCorrupted(t *testing.T) {
967
-	// Negative test
968
-	hnd := New(1024)
969
-
970
-	if hnd.CheckConsistency() {
971
-		t.Fatalf("Unexpected corrupted for %s", hnd)
972
-	}
973
-
974
-	hnd.Set(0)
975
-	if hnd.CheckConsistency() {
976
-		t.Fatalf("Unexpected corrupted for %s", hnd)
977
-	}
978
-
979
-	hnd.Set(1023)
980
-	if hnd.CheckConsistency() {
981
-		t.Fatalf("Unexpected corrupted for %s", hnd)
982
-	}
983
-
984
-	// Try real corrupted ipam handles found in the local store files reported by three docker users,
985
-	// plus a generic ipam handle from docker 1.9.1. This last will fail as well, because of how the
986
-	// last node in the sequence is expressed (This is true for IPAM handle only, because of the broadcast
987
-	// address reservation: last bit). This will allow an application using bitseq that runs a consistency
988
-	// check to detect and replace the 1.9.0/1 old vulnerable handle with the new one.
989
-	input := []*Bitmap{
990
-		{
991
-			bits:       65536,
992
-			unselected: 65412,
993
-			head: &sequence{
994
-				block: 0xffffffff,
995
-				count: 3,
996
-				next: &sequence{
997
-					block: 0xffffffbf,
998
-					count: 0,
999
-					next: &sequence{
1000
-						block: 0xfe98816e,
1001
-						count: 1,
1002
-						next: &sequence{
1003
-							block: 0xffffffff,
1004
-							count: 0,
1005
-							next: &sequence{
1006
-								block: 0xe3bc0000,
1007
-								count: 1,
1008
-								next: &sequence{
1009
-									block: 0x0,
1010
-									count: 2042,
1011
-									next: &sequence{
1012
-										block: 0x1, count: 1,
1013
-										next: &sequence{
1014
-											block: 0x0, count: 0,
1015
-										},
1016
-									},
1017
-								},
1018
-							},
1019
-						},
1020
-					},
1021
-				},
1022
-			},
1023
-		},
1024
-		{
1025
-			bits:       65536,
1026
-			unselected: 65319,
1027
-			head: &sequence{
1028
-				block: 0xffffffff,
1029
-				count: 7,
1030
-				next: &sequence{
1031
-					block: 0xffffff7f,
1032
-					count: 0,
1033
-					next: &sequence{
1034
-						block: 0xffffffff,
1035
-						count: 0,
1036
-						next: &sequence{
1037
-							block: 0x2000000,
1038
-							count: 1,
1039
-							next: &sequence{
1040
-								block: 0x0,
1041
-								count: 2039,
1042
-								next: &sequence{
1043
-									block: 0x1,
1044
-									count: 1,
1045
-									next: &sequence{
1046
-										block: 0x0,
1047
-										count: 0,
1048
-									},
1049
-								},
1050
-							},
1051
-						},
1052
-					},
1053
-				},
1054
-			},
1055
-		},
1056
-		{
1057
-			bits:       65536,
1058
-			unselected: 65456,
1059
-			head: &sequence{
1060
-				block: 0xffffffff, count: 2,
1061
-				next: &sequence{
1062
-					block: 0xfffbffff, count: 0,
1063
-					next: &sequence{
1064
-						block: 0xffd07000, count: 1,
1065
-						next: &sequence{
1066
-							block: 0x0, count: 333,
1067
-							next: &sequence{
1068
-								block: 0x40000000, count: 1,
1069
-								next: &sequence{
1070
-									block: 0x0, count: 1710,
1071
-									next: &sequence{
1072
-										block: 0x1, count: 1,
1073
-										next: &sequence{
1074
-											block: 0x0, count: 0,
1075
-										},
1076
-									},
1077
-								},
1078
-							},
1079
-						},
1080
-					},
1081
-				},
1082
-			},
1083
-		},
1084
-	}
1085
-
1086
-	for idx, hnd := range input {
1087
-		if !hnd.CheckConsistency() {
1088
-			t.Fatalf("Expected corrupted for (%d): %s", idx, hnd)
1089
-		}
1090
-		if hnd.CheckConsistency() {
1091
-			t.Fatalf("Sequence still marked corrupted (%d): %s", idx, hnd)
1092
-		}
1093
-	}
1094
-}
1095
-
1096 966
 func testSetRollover(t *testing.T, serial bool) {
1097 967
 	numBlocks := uint32(8)
1098 968
 	numBits := int(numBlocks * blockLen)
... ...
@@ -11,7 +11,6 @@ import (
11 11
 	"github.com/docker/docker/libnetwork/bitmap"
12 12
 	"github.com/docker/docker/libnetwork/datastore"
13 13
 	"github.com/docker/docker/libnetwork/types"
14
-	"github.com/sirupsen/logrus"
15 14
 )
16 15
 
17 16
 var (
... ...
@@ -101,45 +100,6 @@ func (h *Handle) IsSet(ordinal uint64) bool {
101 101
 	return h.bm.IsSet(ordinal)
102 102
 }
103 103
 
104
-// CheckConsistency checks if the bit sequence is in an inconsistent state and attempts to fix it.
105
-// It looks for a corruption signature that may happen in docker 1.9.0 and 1.9.1.
106
-func (h *Handle) CheckConsistency() error {
107
-	for {
108
-		h.mu.Lock()
109
-		store := h.store
110
-		h.mu.Unlock()
111
-
112
-		if store != nil {
113
-			if err := store.GetObject(datastore.Key(h.Key()...), h); err != nil && err != datastore.ErrKeyNotFound {
114
-				return err
115
-			}
116
-		}
117
-
118
-		h.mu.Lock()
119
-		nh := h.getCopy()
120
-		h.mu.Unlock()
121
-
122
-		if !nh.bm.CheckConsistency() {
123
-			return nil
124
-		}
125
-
126
-		if err := nh.writeToStore(); err != nil {
127
-			if _, ok := err.(types.RetryError); !ok {
128
-				return fmt.Errorf("internal failure while fixing inconsistent bitsequence: %v", err)
129
-			}
130
-			continue
131
-		}
132
-
133
-		logrus.Infof("Fixed inconsistent bit sequence in datastore:\n%s\n%s", h, nh)
134
-
135
-		h.mu.Lock()
136
-		h.bm = nh.bm
137
-		h.mu.Unlock()
138
-
139
-		return nil
140
-	}
141
-}
142
-
143 104
 // set/reset the bit
144 105
 func (h *Handle) apply(op func(*bitmap.Bitmap) (uint64, error)) (uint64, error) {
145 106
 	for {
... ...
@@ -181,36 +181,6 @@ func TestRetrieveFromStore(t *testing.T) {
181 181
 	}
182 182
 }
183 183
 
184
-func TestIsCorrupted(t *testing.T) {
185
-	ds, err := randomLocalStore()
186
-	if err != nil {
187
-		t.Fatal(err)
188
-	}
189
-	// Negative test
190
-	hnd, err := NewHandle("bitseq-test/data/", ds, "test_corrupted", 1024)
191
-	if err != nil {
192
-		t.Fatal(err)
193
-	}
194
-
195
-	if err := hnd.CheckConsistency(); err != nil {
196
-		t.Fatal(err)
197
-	}
198
-
199
-	_ = hnd.Set(0)
200
-	if err := hnd.CheckConsistency(); err != nil {
201
-		t.Fatal(err)
202
-	}
203
-
204
-	_ = hnd.Set(1023)
205
-	if err := hnd.CheckConsistency(); err != nil {
206
-		t.Fatal(err)
207
-	}
208
-
209
-	if err := hnd.CheckConsistency(); err != nil {
210
-		t.Fatal(err)
211
-	}
212
-}
213
-
214 184
 func testSetRollover(t *testing.T, serial bool) {
215 185
 	ds, err := randomLocalStore()
216 186
 	if err != nil {