Skip to content
This repository

change default behavior of database task storage #4080

Merged
merged 2 commits into from 10 months ago

2 participants

Min RK Matthias Bussonnier
Min RK
Owner

The previous default behavior was to create a new table (sqlite) / database (mongodb) for each Hub instance, so that task history would not be shared by subsequent IPython sessions.

I don't think this was the right choice, so this PR switches the default behavior to use the table / database ipython-tasks. The result is that all Hub sessions in a given profile will share history by default, which makes the benefit of the db backends clearer.

Configurable behavior remains the same, only the default is changed.

minrk added some commits
Min RK minrk change default behavior of database task storage
The previous default behavior was to create a new table (sqlite) / database (mongodb) for each Hub instance,
so that task history would not be shared by subsequent IPython sessions.

I don't think this was the right choice,
so this PR switches the default behavior to use the table / database `ipython-tasks`.
The result is that all Hub sessions in a given profile will share history by default,
which makes the benefit of the db backends clearer.

Configurable behavior remains the same, only the default is changed.
8683a41
Min RK minrk quote table name
avoids syntax errors from hyphens
8ed2f5c
Min RK
Owner

Merging in 24 hours unless I hear otherwise.

Matthias Bussonnier
Collaborator

Merging in 24 hours unless I hear otherwise.

Same here. I know you don't like beeing at less that 5 opened PR so I'm reluctant to merge myself.

Min RK minrk merged commit fbb0174 into from
Min RK minrk deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Aug 21, 2013
Min RK minrk change default behavior of database task storage
The previous default behavior was to create a new table (sqlite) / database (mongodb) for each Hub instance,
so that task history would not be shared by subsequent IPython sessions.

I don't think this was the right choice,
so this PR switches the default behavior to use the table / database `ipython-tasks`.
The result is that all Hub sessions in a given profile will share history by default,
which makes the benefit of the db backends clearer.

Configurable behavior remains the same, only the default is changed.
8683a41
Min RK minrk quote table name
avoids syntax errors from hyphens
8ed2f5c
This page is out of date. Refresh to see the latest.
2  IPython/parallel/controller/mongodb.py
@@ -39,7 +39,7 @@ class MongoDB(BaseDB):
39 39 necessary if the default mongodb configuration does not point to your
40 40 mongod instance."""
41 41 )
42   - database = Unicode(config=True,
  42 + database = Unicode("ipython-tasks", config=True,
43 43 help="""The MongoDB database name to use for storing tasks for this session. If unspecified,
44 44 a new database will be created with the Hub's IDENT. Specifying the database will result
45 45 in tasks from previous sessions being available via Clients' db_query and
20 IPython/parallel/controller/sqlitedb.py
@@ -96,7 +96,7 @@ class SQLiteDB(BaseDB):
96 96 location = Unicode('', config=True,
97 97 help="""The directory containing the sqlite task database. The default
98 98 is to use the cluster_dir location.""")
99   - table = Unicode("", config=True,
  99 + table = Unicode("ipython-tasks", config=True,
100 100 help="""The SQLite Table to use for storing tasks for this session. If unspecified,
101 101 a new table will be created with the Hub's IDENT. Specifying the table will result
102 102 in tasks from previous sessions being available via Clients' db_query and
@@ -195,7 +195,7 @@ def _check_table(self):
195 195
196 196 If a bad (old) table does exist, return False
197 197 """
198   - cursor = self._db.execute("PRAGMA table_info(%s)"%self.table)
  198 + cursor = self._db.execute("PRAGMA table_info('%s')"%self.table)
199 199 lines = cursor.fetchall()
200 200 if not lines:
201 201 # table does not exist
@@ -241,7 +241,7 @@ def _init_db(self):
241 241 )
242 242 previous_table = self.table
243 243
244   - self._db.execute("""CREATE TABLE IF NOT EXISTS %s
  244 + self._db.execute("""CREATE TABLE IF NOT EXISTS '%s'
245 245 (msg_id text PRIMARY KEY,
246 246 header dict text,
247 247 metadata dict text,
@@ -333,12 +333,12 @@ def add_record(self, msg_id, rec):
333 333 d['msg_id'] = msg_id
334 334 line = self._dict_to_list(d)
335 335 tups = '(%s)'%(','.join(['?']*len(line)))
336   - self._db.execute("INSERT INTO %s VALUES %s"%(self.table, tups), line)
  336 + self._db.execute("INSERT INTO '%s' VALUES %s"%(self.table, tups), line)
337 337 # self._db.commit()
338 338
339 339 def get_record(self, msg_id):
340 340 """Get a specific Task Record, by msg_id."""
341   - cursor = self._db.execute("""SELECT * FROM %s WHERE msg_id==?"""%self.table, (msg_id,))
  341 + cursor = self._db.execute("""SELECT * FROM '%s' WHERE msg_id==?"""%self.table, (msg_id,))
342 342 line = cursor.fetchone()
343 343 if line is None:
344 344 raise KeyError("No such msg: %r"%msg_id)
@@ -346,7 +346,7 @@ def get_record(self, msg_id):
346 346
347 347 def update_record(self, msg_id, rec):
348 348 """Update the data in an existing record."""
349   - query = "UPDATE %s SET "%self.table
  349 + query = "UPDATE '%s' SET "%self.table
350 350 sets = []
351 351 keys = sorted(rec.keys())
352 352 values = []
@@ -361,13 +361,13 @@ def update_record(self, msg_id, rec):
361 361
362 362 def drop_record(self, msg_id):
363 363 """Remove a record from the DB."""
364   - self._db.execute("""DELETE FROM %s WHERE msg_id==?"""%self.table, (msg_id,))
  364 + self._db.execute("""DELETE FROM '%s' WHERE msg_id==?"""%self.table, (msg_id,))
365 365 # self._db.commit()
366 366
367 367 def drop_matching_records(self, check):
368 368 """Remove a record from the DB."""
369 369 expr,args = self._render_expression(check)
370   - query = "DELETE FROM %s WHERE %s"%(self.table, expr)
  370 + query = "DELETE FROM '%s' WHERE %s"%(self.table, expr)
371 371 self._db.execute(query,args)
372 372 # self._db.commit()
373 373
@@ -399,7 +399,7 @@ def find_records(self, check, keys=None):
399 399 else:
400 400 req = '*'
401 401 expr,args = self._render_expression(check)
402   - query = """SELECT %s FROM %s WHERE %s"""%(req, self.table, expr)
  402 + query = """SELECT %s FROM '%s' WHERE %s"""%(req, self.table, expr)
403 403 cursor = self._db.execute(query, args)
404 404 matches = cursor.fetchall()
405 405 records = []
@@ -410,7 +410,7 @@ def find_records(self, check, keys=None):
410 410
411 411 def get_history(self):
412 412 """get all msg_ids, ordered by time submitted."""
413   - query = """SELECT msg_id FROM %s ORDER by submitted ASC"""%self.table
  413 + query = """SELECT msg_id FROM '%s' ORDER by submitted ASC"""%self.table
414 414 cursor = self._db.execute(query)
415 415 # will be a list of length 1 tuples
416 416 return [ tup[0] for tup in cursor.fetchall()]

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.