Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Status code is 400 for restore api, but actually restore success and has valid response #169

Closed
zhuwenxing opened this issue Jul 19, 2023 · 1 comment

Comments

@zhuwenxing
Copy link
Collaborator

zhuwenxing commented Jul 19, 2023

Current Behavior

Python code

2023-07-19 17:28:14.320 | INFO     | test_restore_backup:test_milvus_restore_with_db_collections:230 - list_backup {'requestId': '95e8da5c-2616-11ee-a7c2-acde48001122', 'msg': 'success', 'data': [{'id': '94ff9d9c-2616-11ee-a7c2-acde48001122', 'state_code': 2, 'name': 'backup_WrIYWSBj', 'backup_timestamp': 1689758892603, 'size': 0}, {'id': '83d2f4b8-2613-11ee-8e8f-acde48001122', 'state_code': 2, 'name': 'backup_XWxeBM7p', 'backup_timestamp': 1689757575317, 'size': 0}, {'id': '3d4dee66-2614-11ee-8e8f-acde48001122', 'state_code': 2, 'name': 'backup_ui4LtScM', 'backup_timestamp': 1689757886486, 'size': 0}, {'id': '7b9a2256-2615-11ee-a7c2-acde48001122', 'state_code': 2, 'name': 'backup_y846cEQI', 'backup_timestamp': 1689758420517, 'size': 0}]}
2023-07-19 17:28:14.401 | INFO     | test_restore_backup:test_milvus_restore_with_db_collections:247 - restore payload: {'async': False, 'backup_name': 'backup_WrIYWSBj', 'db_collections': {'db_RmODSj84': ['restore_backup_MCql68VL', 'restore_backup_2GKqNKmT'], 'db_6xOPCnTA': ['restore_backup_sOujC4XC', 'restore_backup_H0MtzYRO']}, 'collection_suffix': '_bak'}

testcases/test_restore_backup.py:200 (TestRestoreBackup.test_milvus_restore_with_db_collections)
self = <HttpRequest method: POST path: 'restore'>, result = <Response [400]>

    def handle_response(self, result: typing.Any) -> typing.Any:
        """Handle result response."""
        if self.on_handlers and result.status_code in self.on_handlers:
            # Use a registered handler for the returned status code
            return self.on_handlers[result.status_code](result)
        elif self.on_handlers and HttpStatus.ANY in self.on_handlers:
            # If a catch all status handler is provided - use it
            return self.on_handlers[HttpStatus.ANY](result)
        else:
            # If stream option was passed and no content handler
            # was defined, return response
            if self.is_stream:
                return result
    
            # Default response handler
            try:
>               result.raise_for_status()

postman:

POST /api/v1/restore HTTP/1.1
Content-Type: application/json
User-Agent: PostmanRuntime/7.32.3
Accept: */*
Postman-Token: 8e933f8b-d92d-4516-8aef-eb24c9e0597f
Host: localhost:8080
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 352
 
{
"async": false,
"backup_name": "backup_WrIYWSBj",
"db_collections": {
"db_RmODSj84": [
"restore_backup_MCql68VL",
"restore_backup_2GKqNKmT"
],
"db_6xOPCnTA": [
"restore_backup_sOujC4XC",
"restore_backup_H0MtzYRO"
]
},
"collection_suffix": "_bak_v3"
}
 
HTTP/1.1 400 Bad Request
Date: Wed, 19 Jul 2023 09:47:05 GMT
Content-Length: 1048
Content-Type: text/plain; charset=utf-8
 
{"requestId":"2c5e3cc8-2619-11ee-a7c2-acde48001122","msg":"success","data":{"id":"2c5f0efa-2619-11ee-a7c2-acde48001122","state_code":2,"start_time":1689760005,"end_time":1689760025,"collection_restore_tasks":[{"id":"2c605f58-2619-11ee-a7c2-acde48001122","state_code":2,"start_time":1689760005,"target_collection_name":"restore_backup_MCql68VL_bak_v3","restored_size":0,"to_restore_size":0,"progress":100},{"id":"2c61636c-2619-11ee-a7c2-acde48001122","state_code":2,"start_time":1689760005,"target_collection_name":"restore_backup_2GKqNKmT_bak_v3","restored_size":0,"to_restore_size":0,"progress":100},{"id":"2c62c81a-2619-11ee-a7c2-acde48001122","state_code":2,"start_time":1689760005,"target_collection_name":"restore_backup_sOujC4XC_bak_v3","restored_size":0,"to_restore_size":0,"progress":100},{"id":"2c63fb5e-2619-11ee-a7c2-acde48001122","state_code":2,"start_time":1689760005,"target_collection_name":"restore_backup_H0MtzYRO_bak_v3","restored_size":0,"to_restore_size":0,"progress":100}],"restored_size":0,"to_restore_size":0,"progress":100}}

Expected Behavior

No response

Steps To Reproduce

def test_milvus_restore_with_db_collections(self):
        # prepare data
        self._connect()
        names_origin = []
        db_collections = defaultdict(list)
        for i in range(2):
            db_name = cf.gen_unique_str("db")
            db.create_database(db_name)
            db.using_database(db_name)
            for i in range(2):
                collection_name = cf.gen_unique_str(prefix)
                self.prepare_data(name=collection_name, db_name=db_name, nb=3000, is_binary=False, auto_id=True, check_function=False)
                assert collection_name in self.utility_wrap.list_collections()[0]
                names_origin.append(f"{db_name}.{collection_name}")
                db_collections[db_name].append(collection_name)
        db_collections = dict(db_collections)
        log.info(f"db_collections:{db_collections}")
        log.info(f"name_origin:{names_origin}")
        # create backup
        back_up_name = cf.gen_unique_str(backup_prefix)
        payload = {
            "async": False,
            "backup_name": back_up_name,
            "collection_names": names_origin,
        }
        log.info(f"payload: {payload}")
        res = client.create_backup(payload)
        log.info(f"create backup response: {res}")
        res = client.list_backup()
        log.info(f"list_backup {res}")
        if "data" in res:
            all_backup = [r["name"] for r in res["data"]]
        else:
            all_backup = []
        assert back_up_name in all_backup
        # delete db to check that restore can create db if not exist
        for db_name in db_collections:
            db.using_database(db_name)
            all_collections = list_collections()
            for c in all_collections:
                collection = Collection(name=c)
                collection.drop()
            db.drop_database(db_name)
        payload = {"async": False, "backup_name": back_up_name,
                   "db_collections": db_collections,
                   "collection_suffix": suffix}
        log.info(f"restore payload: {payload}")
        res = client.restore_backup(payload)
        log.info(f"restore_backup: {res}")
        for name in names_origin:
            db_name = name.split(".")[0]
            collection_name = name.split(".")[1]
            db.using_database(db_name)
            res, _ = self.utility_wrap.list_collections()
            log.info(f"collection list in db {db_name}: {res}")
            assert collection_name + suffix in res
            self.compare_collections(collection_name, collection_name + suffix)

Environment

No response

Anything else?

log:
backup.log.zip

image
It needs 20s to return, would this be the reason?

@zhuwenxing
Copy link
Collaborator Author

image

if async is true, the status code is also 400

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants