Browse Source
ADHOC: add read needle meta grpc (#3581)
ADHOC: add read needle meta grpc (#3581)
* ADHOC: add read needle meta grpc * add test * nit Co-authored-by: root <root@HQ-10MSTD3EY.roblox.local>pull/3616/head
Eric Yang
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 1536 additions and 1110 deletions
-
2weed/pb/filer_pb/filer.pb.go
-
5weed/pb/filer_pb/filer_grpc.pb.go
-
2weed/pb/iam_pb/iam.pb.go
-
5weed/pb/iam_pb/iam_grpc.pb.go
-
2weed/pb/master_pb/master.pb.go
-
5weed/pb/master_pb/master_grpc.pb.go
-
2weed/pb/mount_pb/mount.pb.go
-
5weed/pb/mount_pb/mount_grpc.pb.go
-
6weed/pb/mq_pb/mq.pb.go
-
5weed/pb/mq_pb/mq_grpc.pb.go
-
6weed/pb/remote_pb/remote.pb.go
-
2weed/pb/s3_pb/s3.pb.go
-
5weed/pb/s3_pb/s3_grpc.pb.go
-
15weed/pb/volume_server.proto
-
2374weed/pb/volume_server_pb/volume_server.pb.go
-
45weed/pb/volume_server_pb/volume_server_grpc.pb.go
-
29weed/server/volume_grpc_read_write.go
-
8weed/storage/erasure_coding/ec_volume.go
-
4weed/storage/needle/needle_read.go
-
2weed/storage/needle/needle_read_page.go
-
8weed/storage/store.go
-
18weed/storage/volume_read.go
-
91weed/storage/volume_read_test.go
2374
weed/pb/volume_server_pb/volume_server.pb.go
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,91 @@ |
|||||
|
package storage |
||||
|
|
||||
|
import ( |
||||
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle" |
||||
|
"github.com/seaweedfs/seaweedfs/weed/storage/super_block" |
||||
|
"github.com/seaweedfs/seaweedfs/weed/storage/types" |
||||
|
"github.com/stretchr/testify/assert" |
||||
|
"testing" |
||||
|
) |
||||
|
|
||||
|
func TestReadNeedMetaWithWritesAndUpdates(t *testing.T) { |
||||
|
dir := t.TempDir() |
||||
|
|
||||
|
v, err := NewVolume(dir, dir, "", 1, NeedleMapInMemory, &super_block.ReplicaPlacement{}, &needle.TTL{}, 0, 0) |
||||
|
if err != nil { |
||||
|
t.Fatalf("volume creation: %v", err) |
||||
|
} |
||||
|
type WriteInfo struct { |
||||
|
offset int64 |
||||
|
size int32 |
||||
|
} |
||||
|
writeInfos := make([]WriteInfo, 30) |
||||
|
mockLastUpdateTime := uint64(1000000000000) |
||||
|
// initialize 20 needles then update first 10 needles
|
||||
|
for i := 1; i <= 30; i++ { |
||||
|
n := newRandomNeedle(uint64(i % 20)) |
||||
|
n.Flags = 0x08 |
||||
|
n.LastModified = mockLastUpdateTime |
||||
|
mockLastUpdateTime += 2000 |
||||
|
offset, _, _, err := v.writeNeedle2(n, true, false) |
||||
|
if err != nil { |
||||
|
t.Fatalf("write needle %d: %v", i, err) |
||||
|
} |
||||
|
writeInfos[i-1] = WriteInfo{offset: int64(offset), size: int32(n.Size)} |
||||
|
} |
||||
|
expectedLastUpdateTime := uint64(1000000000000) |
||||
|
for i := 0; i < 30; i++ { |
||||
|
testNeedle := new(needle.Needle) |
||||
|
testNeedle.Id = types.Uint64ToNeedleId(uint64(i + 1%20)) |
||||
|
testNeedle.Flags = 0x08 |
||||
|
v.readNeedleMetaAt(testNeedle, writeInfos[i].offset, writeInfos[i].size) |
||||
|
actualLastModifiedTime := testNeedle.LastModified |
||||
|
assert.Equal(t, expectedLastUpdateTime, actualLastModifiedTime, "The two words should be the same.") |
||||
|
expectedLastUpdateTime += 2000 |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func TestReadNeedMetaWithDeletesThenWrites(t *testing.T) { |
||||
|
dir := t.TempDir() |
||||
|
|
||||
|
v, err := NewVolume(dir, dir, "", 1, NeedleMapInMemory, &super_block.ReplicaPlacement{}, &needle.TTL{}, 0, 0) |
||||
|
if err != nil { |
||||
|
t.Fatalf("volume creation: %v", err) |
||||
|
} |
||||
|
type WriteInfo struct { |
||||
|
offset int64 |
||||
|
size int32 |
||||
|
} |
||||
|
writeInfos := make([]WriteInfo, 10) |
||||
|
mockLastUpdateTime := uint64(1000000000000) |
||||
|
for i := 1; i <= 10; i++ { |
||||
|
n := newRandomNeedle(uint64(i % 5)) |
||||
|
n.Flags = 0x08 |
||||
|
n.LastModified = mockLastUpdateTime |
||||
|
mockLastUpdateTime += 2000 |
||||
|
offset, _, _, err := v.writeNeedle2(n, true, false) |
||||
|
if err != nil { |
||||
|
t.Fatalf("write needle %d: %v", i, err) |
||||
|
} |
||||
|
if i < 5 { |
||||
|
size, err := v.deleteNeedle2(n) |
||||
|
if err != nil { |
||||
|
t.Fatalf("delete needle %d: %v", i, err) |
||||
|
} |
||||
|
writeInfos[i-1] = WriteInfo{offset: int64(offset), size: int32(size)} |
||||
|
} else { |
||||
|
writeInfos[i-1] = WriteInfo{offset: int64(offset), size: int32(n.Size)} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
expectedLastUpdateTime := uint64(1000000000000) |
||||
|
for i := 0; i < 10; i++ { |
||||
|
testNeedle := new(needle.Needle) |
||||
|
testNeedle.Id = types.Uint64ToNeedleId(uint64(i + 1%5)) |
||||
|
testNeedle.Flags = 0x08 |
||||
|
v.readNeedleMetaAt(testNeedle, writeInfos[i].offset, writeInfos[i].size) |
||||
|
actualLastModifiedTime := testNeedle.LastModified |
||||
|
assert.Equal(t, expectedLastUpdateTime, actualLastModifiedTime, "The two words should be the same.") |
||||
|
expectedLastUpdateTime += 2000 |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue