Skip to content

Commit

Permalink
better logging / reconnect v0.2.23
Browse files Browse the repository at this point in the history
  • Loading branch information
phact committed Aug 19, 2024
1 parent 60920e3 commit 2c09f6a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.2.22
v0.2.23
16 changes: 10 additions & 6 deletions impl/astra_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
from cassandra.concurrent import execute_concurrent, execute_concurrent_with_args
from fastapi import HTTPException

from cassandra import ConsistencyLevel, Unauthorized
from cassandra import ConsistencyLevel, Unauthorized, ProtocolVersion
from cassandra.auth import PlainTextAuthProvider
from cassandra.cluster import Cluster, DriverException, NoHostAvailable
from cassandra.policies import RetryPolicy
from cassandra.policies import RetryPolicy, ExponentialReconnectionPolicy
from cassandra.query import (
UNSET_VALUE,
SimpleStatement,
Expand Down Expand Up @@ -340,7 +340,11 @@ def connect(self, retry=False):
cloud_config = {"secure_connect_bundle": bundlepath}
auth_provider = PlainTextAuthProvider(CASSANDRA_USER, token)
cluster = Cluster(
cloud=cloud_config, auth_provider=auth_provider, connect_timeout=60
cloud=cloud_config,
auth_provider=auth_provider,
connect_timeout=60,
protocol_version=ProtocolVersion.V4,
reconnection_policy=ExponentialReconnectionPolicy(base_delay=1, max_delay=60)
)
session = cluster.connect()
session.default_consistency_level = ConsistencyLevel.LOCAL_QUORUM
Expand Down Expand Up @@ -1377,16 +1381,16 @@ def upsert_table_from_dict(self, table_name : str, obj : Dict):
{placeholders}
);"""

statement = self.session.prepare(query_string)
statement.consistency_level = ConsistencyLevel.QUORUM
try:
statement = self.session.prepare(query_string)
statement.consistency_level = ConsistencyLevel.QUORUM
response = self.session.execute(
statement,
tuple(values_list)
)
logger.debug(f"upserted {table_name}: {obj}")
except Exception as e:
logger.error(f"failed to upsert {table_name}: {obj}")
logger.error(f"failed to upsert {table_name}: {obj}, {query_string}")
raise e

def upsert_table_from_base_model(self, table_name : str, obj : BaseModel):
Expand Down

0 comments on commit 2c09f6a

Please sign in to comment.