mirror of
https://github.com/lancedb/lancedb.git
synced 2025-12-26 06:39:57 +00:00
Adds capability to the remote python SDK to retry requests (fixes #911)
This can be configured through environment:
- `LANCE_CLIENT_MAX_RETRIES`= total number of retries. Set to 0 to
disable retries. default = 3
- `LANCE_CLIENT_CONNECT_RETRIES` = number of times to retry request in
case of TCP connect failure. default = 3
- `LANCE_CLIENT_READ_RETRIES` = number of times to retry request in case
of HTTP request failure. default = 3
- `LANCE_CLIENT_RETRY_STATUSES` = http statuses for which the request
will be retried. passed as comma separated list of ints. default `500,
502, 503`
- `LANCE_CLIENT_RETRY_BACKOFF_FACTOR` = controls time between retry
requests. see
[here](23f2287eb5/src/urllib3/util/retry.py (L141-L146)).
default = 0.25
Only read requests will be retried:
- list table names
- query
- describe table
- list table indices
This does not add retry capabilities for writes as it could possibly
cause issues in the case where the retried write isn't idempotent. For
example, in the case where the LB times-out the request but the server
completes the request anyway, we might not want to blindly retry an
insert request.
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
# Copyright 2023 LanceDB Developers
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import pyarrow as pa
|
|
|
|
import lancedb
|
|
from lancedb.remote.client import VectorQuery, VectorQueryResult
|
|
|
|
|
|
class FakeLanceDBClient:
|
|
def close(self):
|
|
pass
|
|
|
|
def query(self, table_name: str, query: VectorQuery) -> VectorQueryResult:
|
|
assert table_name == "test"
|
|
t = pa.schema([]).empty_table()
|
|
return VectorQueryResult(t)
|
|
|
|
def post(self, path: str):
|
|
pass
|
|
|
|
def mount_retry_adapter_for_table(self, table_name: str):
|
|
pass
|
|
|
|
|
|
def test_remote_db():
|
|
conn = lancedb.connect("db://client-will-be-injected", api_key="fake")
|
|
setattr(conn, "_client", FakeLanceDBClient())
|
|
|
|
table = conn["test"]
|
|
table.search([1.0, 2.0]).to_pandas()
|