Hi,
I have a problem of bulk deleting from a sharded session, I tried to
search the previous posts without any finding.
I have the following table:
usersession_table = Table('kg_usersession', meta,
Column('session_id', String(32),
primary_key=True),
Column('user_id', BigInteger, index=True,
nullable=False),
Column('create_time', DateTime, index=True),
Column('expire_time', DateTime, index=True),
Column('site', String(10)),
mysql_engine='MyISAM'
)
I use horizontal sharding by "session_id", with the following shard
chooser:
def shard_chooser(mapper, instance, clause=None):
if instance:
return shard_value(instance.session_id)
Then, I want to delete all record earlier than a given expire_time,
with the following code:
session.query(UserSession).filter(UserSession.expire_time<=expire_time).delete();
It raises an error:
Traceback (most recent call last):
File "delete_expire_session.py", line 20, in <module>
delete_expire_session(expire_time)
File "delete_expire_session.py", line 13, in delete_expire_session
session.query(UserSession).filter(UserSession.expire_time<=expire_time).delete();
File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.5-
py2.6.egg/sqlalchemy/orm/query.py", line 2142, in delete
result = session.execute(delete_stmt, params=self._params)
File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.5-
py2.6.egg/sqlalchemy/orm/session.py", line 726, in execute
engine = self.get_bind(mapper, clause=clause, **kw)
File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.5-
py2.6.egg/sqlalchemy/ext/horizontal_shard.py", line 73, in get_bind
return self.__binds[shard_id]
KeyError: None
I guess shard_chooser return None because of "instance" is None at
runtime. I read from the docs: shard_chooser maybe in "some round-
robin scheme". But I don't have any idea what does it exactly mean in
my case.
I appreciate any advice.
Best regards!
can
PS: you can access partial source code in the gist:
https://gist.github.com/930708
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.