CentaurusInfra / global-resource-service

Apache License 2.0
0 stars 4 forks source link

Add function GetBatchNodeIDsInquiry for redis store #155

Closed q131172019 closed 1 year ago

q131172019 commented 1 year ago

This PR is to 1) add function BatchLogicalNodsInquiry for Redis store, which is used by batch logicalNode status inquiry. 2) add UT test for function BatchLogicalNodesInquiry

Please Note: this PR only support Redis-server local only, another new PR will be for Redis-server remote support.

The codes have been tested successfully in local MAC development and my AWS integration test environment (500K nodes/2 regions/20 schedulers).

  1. UT in local MAC development:

    
    carl@Carls-MacBook-Pro redis % go test -v
    === RUN   TestNewRedisClient
    --- PASS: TestNewRedisClient (0.00s)
    === RUN   TestSetGettString
    --- PASS: TestSetGettString (0.00s)
    === RUN   TestPersistNodes
    --- PASS: TestPersistNodes (0.00s)
    === RUN   TestPersistNodeStoreStatus
    --- PASS: TestPersistNodeStoreStatus (0.00s)
    === RUN   TestPersistVirtualNodesAssignments
    --- PASS: TestPersistVirtualNodesAssignments (0.00s)
    === RUN   TestBatchLogicalNodeInquiry
    redis_test.go:215: 
        First test is starting
    redis_test.go:259: Scan (2) logical nodes and actually get (2) logical nodes
    redis_test.go:262: Index #(0): 
    redis_test.go:263: =================
    redis_test.go:264: Id:        (0003)
    redis_test.go:265: Region:    (1002)
    redis_test.go:266: RP:        (1002)
    redis_test.go:262: Index #(1): 
    redis_test.go:263: =================
    redis_test.go:264: Id:        (0002)
    redis_test.go:265: Region:    (1001)
    redis_test.go:266: RP:        (1001)
    redis_test.go:268: 
        First test is OK
    
    redis_test.go:271: 
        Second test is starting
    redis_test.go:316: Scan (10) logical nodes and actually get (12) logical nodes
    redis_test.go:317: 
        Second test is OK
    
    redis_test.go:320: 
        Third test is starting
    redis_test.go:332: Scan (1000) logical nodes and actually get (1000) logical nodes
    redis_test.go:333: 
        Third test is OK
    
    redis_test.go:336: 
        Fourth test is starting
    redis_test.go:348: Scan (2000) logical nodes and actually get (2003) logical nodes
    redis_test.go:349: 
        Fouth test is OK
    
    redis_test.go:352: 
        The fifth test is starting
    redis_test.go:360: Scan (20000) logical nodes and actually get (10002) logical nodes
    redis_test.go:361: 
        Fifth test is OK

--- PASS: TestBatchLogicalNodeInquiry (1.45s) PASS ok global-resource-service/resource-management/pkg/store/redis 1.639s

carl@Carls-MacBook-Pro redis % go test
PASS ok global-resource-service/resource-management/pkg/store/redis 1.781s


Integration test for inquiry on AWS EC2 instance running service_api:

ubuntu@ip-172-31-8-82:~/go/src/GRS/resource-management/pkg/store/redis$ go test -v === RUN TestNewRedisClient --- PASS: TestNewRedisClient (0.00s) === RUN TestBatchLogicalNodeInquiry redis_test.go:316: Scan (10) logical nodes and actually get (10) logical nodes redis_test.go:317: Second test is OK

redis_test.go:320:
    Third test is starting
redis_test.go:332: Scan (1000) logical nodes and actually get (1001) logical nodes
redis_test.go:333:
    Third test is OK

redis_test.go:336:
    Fourth test is starting
redis_test.go:348: Scan (2000) logical nodes and actually get (2000) logical nodes
redis_test.go:349:
    Fouth test is OK

redis_test.go:352:
    The fifth test is starting
redis_test.go:360: Scan (20000) logical nodes and actually get (20000) logical nodes
redis_test.go:361:
    Fifth test is OK

--- PASS: TestBatchLogicalNodeInquiry (3.09s) PASS ok global-resource-service/resource-management/pkg/store/redis 3.095s

ubuntu@ip-172-31-8-82:~/go/src/GRS/resource-management/pkg/store/redis$ go test -v === RUN TestNewRedisClient --- PASS: TestNewRedisClient (0.00s) === RUN TestBatchLogicalNodeInquiry redis_test.go:316: Scan (10) logical nodes and actually get (11) logical nodes redis_test.go:317: Second test is OK

redis_test.go:320:
    Third test is starting
redis_test.go:332: Scan (1000) logical nodes and actually get (1000) logical nodes
redis_test.go:333:
    Third test is OK

redis_test.go:336:
    Fourth test is starting
redis_test.go:348: Scan (2000) logical nodes and actually get (2000) logical nodes
redis_test.go:349:
    Fouth test is OK

redis_test.go:352:
    The fifth test is starting
redis_test.go:360: Scan (3000) logical nodes and actually get (3000) logical nodes
redis_test.go:361:
    Fifth test is OK

--- PASS: TestBatchLogicalNodeInquiry (0.87s) PASS ok global-resource-service/resource-management/pkg/store/redis 0.877s


Integration test for inquiry on cross-region machine:

ubuntu@ip-172-31-17-152:~/go/src/GRS/resource-management/pkg/store/redis$ go test -v === RUN TestNewRedisClient --- PASS: TestNewRedisClient (0.00s) === RUN TestBatchLogicalNodeInquiry redis_test.go:316: Scan (10) logical nodes and actually get (11) logical nodes redis_test.go:317: Second test is OK

redis_test.go:320:
    Third test is starting
redis_test.go:332: Scan (1000) logical nodes and actually get (1000) logical nodes
redis_test.go:333:
    Third test is OK

redis_test.go:336:
    Fourth test is starting
redis_test.go:348: Scan (2000) logical nodes and actually get (2000) logical nodes
redis_test.go:349:
    Fouth test is OK

redis_test.go:352:
    The fifth test is starting
redis_test.go:360: Scan (3000) logical nodes and actually get (3000) logical nodes
redis_test.go:361:
    Fifth test is OK

--- PASS: TestBatchLogicalNodeInquiry (124.49s) PASS ok global-resource-service/resource-management/pkg/store/redis 124.491s

ubuntu@ip-172-31-17-152:~/go/src/GRS/resource-management/pkg/store/redis$ go test -v === RUN TestNewRedisClient --- PASS: TestNewRedisClient (0.00s) === RUN TestBatchLogicalNodeInquiry redis_test.go:316: Scan (10) logical nodes and actually get (11) logical nodes redis_test.go:317: Second test is OK

redis_test.go:320:
    Third test is starting
redis_test.go:332: Scan (1000) logical nodes and actually get (1000) logical nodes
redis_test.go:333:
    Third test is OK

redis_test.go:336:
    Fourth test is starting
redis_test.go:348: Scan (2000) logical nodes and actually get (2000) logical nodes
redis_test.go:349:
    Fouth test is OK

redis_test.go:352:
    The fifth test is starting
redis_test.go:360: Scan (3000) logical nodes and actually get (3000) logical nodes
redis_test.go:361:
    Fifth test is OK

--- PASS: TestBatchLogicalNodeInquiry (125.11s) PASS ok global-resource-service/resource-management/pkg/store/redis 125.115s

sonyafenge commented 1 year ago

Looks like this only support redis-server local, we may need add remote support.

sonyafenge commented 1 year ago

run the code from remote client and received node number doesn't match:

store := redis.NewRedisClient(redisIp, false)
    requiredNum := testCfg.batchNodeNum + testCfg.singleNodeNum
    logicalNodes := store.BatchLogicalNodesInquiry(requiredNum)
    klog.V(6).Infof("Total %v nodes required from redis server: %v, Total nodes got from redis: %v, detailes: %v\n", requiredNum, redisIp, len(logicalNodes), logicalNodes)

3 different Results with 3 runs:

I0902 16:33:09.593263  157647 singleNodeQuery.go:91] Total nodes required from redis: 11, Total nodes got from redis: 15, detailes: &[0xc000224000 0xc0002240c0 0xc000224180 0xc000224240 0xc000224300 0xc0002243c0 0xc000224480 0xc000224540 0xc000224600 0xc0002246c0 0xc000224780 0xc000224840 0xc000224900 0xc0002249c0 0xc000224a80]
I0902 16:34:35.663615  157960 singleNodeQuery.go:91] Total 11 nodes required from redis server: 104.198.205.207, Total nodes got from redis: 7, detailes: [0xc000136000 0xc0001360c0 0xc000136180 0xc000136240 0xc000136300 0xc0001363c0 0xc000136480]
I0902 16:38:16.487011  158116 singleNodeQuery.go:91] Total 11 nodes required from redis server: 104.198.205.207, Total nodes got from redis: 10, detailes: [0xc000130000 0xc0001300c0 0xc000130180 0xc000130240 0xc000130300 0xc0001303c0 0xc000130480 0xc000130540 0xc000130600 0xc0001306c0]