From 0e165e70e52670d5a2986393662abdc025499035 Mon Sep 17 00:00:00 2001 From: Tiger Date: Fri, 12 Jun 2020 11:26:18 +0530 Subject: [PATCH 1/3] use assert to find whether, the async compression/encryption able to fit the destination block in the allocated space. Allocated space is calculated using (item.end-item.start) + padding. Signed-off-by: Tiger --- table/builder.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/table/builder.go b/table/builder.go index d32d9c6aa..53970a3e5 100644 --- a/table/builder.go +++ b/table/builder.go @@ -154,8 +154,12 @@ func (b *Builder) handleBlock() { // that means the data from this block cannot be stored in its existing // location and trying to copy it over would mean we would over-write // some data of the next block. - y.AssertTruef(uint32(len(blockBuf)) <= item.end+padding, - "newend: %d item.end: %d padding: %d", len(blockBuf), item.end, padding) + allocatedSpace := (item.end - item.start) + padding + y.AssertTruef(uint32(len(blockBuf)) <= allocatedSpace, + "newend: %d item.end: %d padding: %d", + (allocatedSpace-uint32(len(blockBuf)))+item.end, + item.end, + padding) // Acquire the buflock here. The builder.grow function might change // the b.buf while this goroutine was running. From 9b1e4582fd1dd3518094f10e239545c98b88acba Mon Sep 17 00:00:00 2001 From: Tiger Date: Fri, 12 Jun 2020 17:19:29 +0530 Subject: [PATCH 2/3] fix comment Signed-off-by: Tiger --- table/builder.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/table/builder.go b/table/builder.go index 53970a3e5..5261ac620 100644 --- a/table/builder.go +++ b/table/builder.go @@ -149,17 +149,13 @@ func (b *Builder) handleBlock() { blockBuf = eBlock } - // The newend should always be less than or equal to the original end - // plus the padding. If the new end is greater than item.end+padding - // that means the data from this block cannot be stored in its existing - // location and trying to copy it over would mean we would over-write - // some data of the next block. + // BlockBuf should always less than or equal to allocated space. If the blockBuf is greater + // than allocated space that means the data from this block cannot be stored in its + // existing location and trying to copy it over would mean we would over-writesome data + // of the next block. allocatedSpace := (item.end - item.start) + padding - y.AssertTruef(uint32(len(blockBuf)) <= allocatedSpace, - "newend: %d item.end: %d padding: %d", - (allocatedSpace-uint32(len(blockBuf)))+item.end, - item.end, - padding) + y.AssertTruef(uint32(len(blockBuf)) <= allocatedSpace, "newend: %d oldend: %d padding: %d", + item.start+uint32(len(blockBuf)), item.end, padding) // Acquire the buflock here. The builder.grow function might change // the b.buf while this goroutine was running. From 545e068f5b9993ccf153f123b39b033ac0fd48b3 Mon Sep 17 00:00:00 2001 From: Tiger Date: Mon, 15 Jun 2020 13:10:20 +0530 Subject: [PATCH 3/3] minor Signed-off-by: Tiger --- table/builder.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/table/builder.go b/table/builder.go index 5261ac620..adf064d9a 100644 --- a/table/builder.go +++ b/table/builder.go @@ -151,9 +151,9 @@ func (b *Builder) handleBlock() { // BlockBuf should always less than or equal to allocated space. If the blockBuf is greater // than allocated space that means the data from this block cannot be stored in its - // existing location and trying to copy it over would mean we would over-writesome data + // existing location and trying to copy it over would mean we would over-write some data // of the next block. - allocatedSpace := (item.end - item.start) + padding + allocatedSpace := (item.end - item.start) + padding + 1 y.AssertTruef(uint32(len(blockBuf)) <= allocatedSpace, "newend: %d oldend: %d padding: %d", item.start+uint32(len(blockBuf)), item.end, padding)