Browse Source

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 2 years ago
parent
commit
6f08fe20e9

+ 0 - 15
libnetwork/bitmap/sequence.go

@@ -231,21 +231,6 @@ func (h *Bitmap) IsSet(ordinal uint64) bool {
 	return err != nil
 	return err != nil
 }
 }
 
 
-// CheckConsistency checks if the bit sequence is in an inconsistent state and attempts to fix it.
-// It looks for a corruption signature that may happen in docker 1.9.0 and 1.9.1.
-func (h *Bitmap) CheckConsistency() bool {
-	corrupted := false
-	for p, c := h.head, h.head.next; c != nil; c = c.next {
-		if c.count == 0 {
-			corrupted = true
-			p.next = c.next
-			continue // keep same p
-		}
-		p = c
-	}
-	return corrupted
-}
-
 // set/reset the bit
 // set/reset the bit
 func (h *Bitmap) set(ordinal, start, end uint64, any bool, release bool, serial bool) (uint64, error) {
 func (h *Bitmap) set(ordinal, start, end uint64, any bool, release bool, serial bool) (uint64, error) {
 	var (
 	var (

+ 0 - 130
libnetwork/bitmap/sequence_test.go

@@ -963,136 +963,6 @@ func TestAllocateRandomDeallocateSerialize(t *testing.T) {
 	}
 	}
 }
 }
 
 
-func TestIsCorrupted(t *testing.T) {
-	// Negative test
-	hnd := New(1024)
-
-	if hnd.CheckConsistency() {
-		t.Fatalf("Unexpected corrupted for %s", hnd)
-	}
-
-	hnd.Set(0)
-	if hnd.CheckConsistency() {
-		t.Fatalf("Unexpected corrupted for %s", hnd)
-	}
-
-	hnd.Set(1023)
-	if hnd.CheckConsistency() {
-		t.Fatalf("Unexpected corrupted for %s", hnd)
-	}
-
-	// Try real corrupted ipam handles found in the local store files reported by three docker users,
-	// plus a generic ipam handle from docker 1.9.1. This last will fail as well, because of how the
-	// last node in the sequence is expressed (This is true for IPAM handle only, because of the broadcast
-	// address reservation: last bit). This will allow an application using bitseq that runs a consistency
-	// check to detect and replace the 1.9.0/1 old vulnerable handle with the new one.
-	input := []*Bitmap{
-		{
-			bits:       65536,
-			unselected: 65412,
-			head: &sequence{
-				block: 0xffffffff,
-				count: 3,
-				next: &sequence{
-					block: 0xffffffbf,
-					count: 0,
-					next: &sequence{
-						block: 0xfe98816e,
-						count: 1,
-						next: &sequence{
-							block: 0xffffffff,
-							count: 0,
-							next: &sequence{
-								block: 0xe3bc0000,
-								count: 1,
-								next: &sequence{
-									block: 0x0,
-									count: 2042,
-									next: &sequence{
-										block: 0x1, count: 1,
-										next: &sequence{
-											block: 0x0, count: 0,
-										},
-									},
-								},
-							},
-						},
-					},
-				},
-			},
-		},
-		{
-			bits:       65536,
-			unselected: 65319,
-			head: &sequence{
-				block: 0xffffffff,
-				count: 7,
-				next: &sequence{
-					block: 0xffffff7f,
-					count: 0,
-					next: &sequence{
-						block: 0xffffffff,
-						count: 0,
-						next: &sequence{
-							block: 0x2000000,
-							count: 1,
-							next: &sequence{
-								block: 0x0,
-								count: 2039,
-								next: &sequence{
-									block: 0x1,
-									count: 1,
-									next: &sequence{
-										block: 0x0,
-										count: 0,
-									},
-								},
-							},
-						},
-					},
-				},
-			},
-		},
-		{
-			bits:       65536,
-			unselected: 65456,
-			head: &sequence{
-				block: 0xffffffff, count: 2,
-				next: &sequence{
-					block: 0xfffbffff, count: 0,
-					next: &sequence{
-						block: 0xffd07000, count: 1,
-						next: &sequence{
-							block: 0x0, count: 333,
-							next: &sequence{
-								block: 0x40000000, count: 1,
-								next: &sequence{
-									block: 0x0, count: 1710,
-									next: &sequence{
-										block: 0x1, count: 1,
-										next: &sequence{
-											block: 0x0, count: 0,
-										},
-									},
-								},
-							},
-						},
-					},
-				},
-			},
-		},
-	}
-
-	for idx, hnd := range input {
-		if !hnd.CheckConsistency() {
-			t.Fatalf("Expected corrupted for (%d): %s", idx, hnd)
-		}
-		if hnd.CheckConsistency() {
-			t.Fatalf("Sequence still marked corrupted (%d): %s", idx, hnd)
-		}
-	}
-}
-
 func testSetRollover(t *testing.T, serial bool) {
 func testSetRollover(t *testing.T, serial bool) {
 	numBlocks := uint32(8)
 	numBlocks := uint32(8)
 	numBits := int(numBlocks * blockLen)
 	numBits := int(numBlocks * blockLen)

+ 0 - 40
libnetwork/bitseq/sequence.go

@@ -11,7 +11,6 @@ import (
 	"github.com/docker/docker/libnetwork/bitmap"
 	"github.com/docker/docker/libnetwork/bitmap"
 	"github.com/docker/docker/libnetwork/datastore"
 	"github.com/docker/docker/libnetwork/datastore"
 	"github.com/docker/docker/libnetwork/types"
 	"github.com/docker/docker/libnetwork/types"
-	"github.com/sirupsen/logrus"
 )
 )
 
 
 var (
 var (
@@ -101,45 +100,6 @@ func (h *Handle) IsSet(ordinal uint64) bool {
 	return h.bm.IsSet(ordinal)
 	return h.bm.IsSet(ordinal)
 }
 }
 
 
-// CheckConsistency checks if the bit sequence is in an inconsistent state and attempts to fix it.
-// It looks for a corruption signature that may happen in docker 1.9.0 and 1.9.1.
-func (h *Handle) CheckConsistency() error {
-	for {
-		h.mu.Lock()
-		store := h.store
-		h.mu.Unlock()
-
-		if store != nil {
-			if err := store.GetObject(datastore.Key(h.Key()...), h); err != nil && err != datastore.ErrKeyNotFound {
-				return err
-			}
-		}
-
-		h.mu.Lock()
-		nh := h.getCopy()
-		h.mu.Unlock()
-
-		if !nh.bm.CheckConsistency() {
-			return nil
-		}
-
-		if err := nh.writeToStore(); err != nil {
-			if _, ok := err.(types.RetryError); !ok {
-				return fmt.Errorf("internal failure while fixing inconsistent bitsequence: %v", err)
-			}
-			continue
-		}
-
-		logrus.Infof("Fixed inconsistent bit sequence in datastore:\n%s\n%s", h, nh)
-
-		h.mu.Lock()
-		h.bm = nh.bm
-		h.mu.Unlock()
-
-		return nil
-	}
-}
-
 // set/reset the bit
 // set/reset the bit
 func (h *Handle) apply(op func(*bitmap.Bitmap) (uint64, error)) (uint64, error) {
 func (h *Handle) apply(op func(*bitmap.Bitmap) (uint64, error)) (uint64, error) {
 	for {
 	for {

+ 0 - 30
libnetwork/bitseq/sequence_test.go

@@ -181,36 +181,6 @@ func TestRetrieveFromStore(t *testing.T) {
 	}
 	}
 }
 }
 
 
-func TestIsCorrupted(t *testing.T) {
-	ds, err := randomLocalStore()
-	if err != nil {
-		t.Fatal(err)
-	}
-	// Negative test
-	hnd, err := NewHandle("bitseq-test/data/", ds, "test_corrupted", 1024)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	if err := hnd.CheckConsistency(); err != nil {
-		t.Fatal(err)
-	}
-
-	_ = hnd.Set(0)
-	if err := hnd.CheckConsistency(); err != nil {
-		t.Fatal(err)
-	}
-
-	_ = hnd.Set(1023)
-	if err := hnd.CheckConsistency(); err != nil {
-		t.Fatal(err)
-	}
-
-	if err := hnd.CheckConsistency(); err != nil {
-		t.Fatal(err)
-	}
-}
-
 func testSetRollover(t *testing.T, serial bool) {
 func testSetRollover(t *testing.T, serial bool) {
 	ds, err := randomLocalStore()
 	ds, err := randomLocalStore()
 	if err != nil {
 	if err != nil {