本文整理汇总了Python中skytools.fq_name函数的典型用法代码示例。如果您正苦于以下问题:Python fq_name函数的具体用法?Python fq_name怎么用?Python fq_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fq_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: work
def work(self):
"""Syncer main function."""
# 'SELECT 1' and COPY must use same snapshot, so change isolation level.
dst_db = self.get_database('db', isolation_level = skytools.I_REPEATABLE_READ)
pnode, ploc = self.get_provider_location(dst_db)
dst_tables, names = self.get_tables(dst_db)
if len(self.args) > 2:
tlist = self.args[2:]
else:
tlist = names
for tbl in tlist:
tbl = skytools.fq_name(tbl)
if not tbl in dst_tables:
self.log.warning('Table not subscribed: %s' % tbl)
continue
t2 = dst_tables[tbl]
if t2.merge_state != 'ok':
self.log.warning('Table %s not synced yet, no point' % tbl)
continue
pnode, ploc, wname = find_copy_source(self, self.queue_name, tbl, pnode, ploc)
self.log.info('%s: Using node %s as provider', tbl, pnode)
if wname is None:
wname = self.consumer_name
self.downstream_worker_name = wname
self.process_one_table(tbl, t2, dst_db, pnode, ploc)
# signal caller about bad tables
sys.exit(self.bad_tables)
示例2: subscriber_add_seq
def subscriber_add_seq(self, seq_list):
src_db = self.get_database('provider_db')
src_curs = src_db.cursor()
dst_db = self.get_database('subscriber_db')
dst_curs = dst_db.cursor()
prov_list = self.get_provider_seqs()
full_list = self.get_all_seqs(dst_curs)
cur_list = self.get_subscriber_seq_list()
if not seq_list and self.options.all:
seq_list = prov_list
for seq in seq_list:
seq = skytools.fq_name(seq)
if seq not in prov_list:
self.log.error('Seq %s does not exist on provider side' % seq)
continue
if seq not in full_list:
self.log.error('Seq %s does not exist on subscriber side' % seq)
continue
if seq in cur_list:
self.log.info('Seq %s already subscribed' % seq)
continue
self.log.info('Adding sequence: %s' % seq)
q = "select londiste.subscriber_add_seq(%s, %s)"
dst_curs.execute(q, [self.pgq_queue_name, seq])
dst_db.commit()
示例3: cmd_add_seq
def cmd_add_seq(self, *args):
"""Attach seqs(s) to local node."""
dst_db = self.get_database('db')
dst_curs = dst_db.cursor()
src_db = self.get_provider_db()
src_curs = src_db.cursor()
src_seqs = self.fetch_seqs(src_curs)
dst_seqs = self.fetch_seqs(dst_curs)
src_db.commit()
self.sync_seq_list(dst_curs, src_seqs, dst_seqs)
dst_db.commit()
args = self.expand_arg_list(dst_db, 'S', False, args)
# pick proper create flags
create = self.options.create_only
if not create and self.options.create:
create = 'full'
fmap = {
"full": skytools.T_SEQUENCE,
}
create_flags = 0
if create:
for f in create.split(','):
if f not in fmap:
raise Exception("bad --create-only flag: " + f)
create_flags += fmap[f]
# seems ok
for seq in args:
seq = skytools.fq_name(seq)
self.add_seq(src_db, dst_db, seq, create_flags)
dst_db.commit()
示例4: solve_globbing
def solve_globbing(self, args, full_list, full_map, reverse_map):
def glob2regex(s):
s = s.replace('.', '[.]').replace('?', '.').replace('*', '.*')
return '^%s$' % s
res_map = {}
res_list = []
err = 0
for a in args:
if a.find('*') >= 0 or a.find('?') >= 0:
if a.find('.') < 0:
a = 'public.' + a
rc = re.compile(glob2regex(a))
for x in full_list:
if rc.match(x):
if not x in res_map:
res_map[x] = 1
res_list.append(x)
else:
a = skytools.fq_name(a)
if a in res_map:
continue
elif a in full_map:
res_list.append(a)
res_map[a] = 1
elif a in reverse_map:
self.log.info("%s already processed" % a)
else:
self.log.warning("%s not available" % a)
err = 1
if err:
raise UsageError("Cannot proceed")
return res_list
示例5: need_execute
def need_execute(self, curs, local_tables, local_seqs):
# if no attrs, always execute
if not self.attrs:
return True
matched = 0
missed = 0
good_list = []
miss_list = []
for m in META_MATCHERS:
k = m.get_key()
if k not in self.attrs:
continue
for v in self.attrs[k]:
fqname = skytools.fq_name(v)
if m.match(fqname, curs, local_tables, local_seqs):
matched += 1
good_list.append(v)
else:
missed += 1
miss_list.append(v)
# should be drop out early?
if matched > 0 and missed == 0:
return True
elif missed > 0 and matched == 0:
return False
elif missed == 0 and matched == 0:
# should not happen, but lets restore old behaviour?
return True
else:
raise Exception("SQL only partially matches local setup: matches=%r misses=%r" % (good_list, miss_list))
示例6: cmd_add_table
def cmd_add_table(self, *args):
"""Attach table(s) to local node."""
self.load_local_info()
src_db = self.get_provider_db()
if not self.is_root():
src_curs = src_db.cursor()
src_tbls = self.fetch_set_tables(src_curs)
src_db.commit()
dst_db = self.get_database('db')
dst_curs = dst_db.cursor()
dst_tbls = self.fetch_set_tables(dst_curs)
if self.is_root():
src_tbls = dst_tbls
else:
self.sync_table_list(dst_curs, src_tbls, dst_tbls)
dst_db.commit()
needs_tbl = self.handler_needs_table()
args = self.expand_arg_list(dst_db, 'r', False, args, needs_tbl)
# dont check for exist/not here (root handling)
if not self.is_root() and not self.options.expect_sync and not self.options.find_copy_node:
problems = False
for tbl in args:
tbl = skytools.fq_name(tbl)
if (tbl in src_tbls) and not src_tbls[tbl]['local']:
self.log.error("Table %s does not exist on provider, need to switch to different provider" % tbl)
problems = True
if problems:
self.log.error("Problems, canceling operation")
sys.exit(1)
# pick proper create flags
if self.options.create_full:
create_flags = skytools.T_ALL
elif self.options.create:
create_flags = skytools.T_TABLE | skytools.T_PKEY
else:
create_flags = 0
# sanity check
if self.options.dest_table and len(args) > 1:
self.log.error("--dest-table can be given only for single table")
sys.exit(1)
# not implemented
if self.options.find_copy_node and create_flags != 0:
self.log.error("--find-copy-node does not work with --create")
sys.exit(1)
# seems ok
for tbl in args:
self.add_table(src_db, dst_db, tbl, create_flags, src_tbls)
# wait
if self.options.wait_sync:
self.wait_for_sync(dst_db)
示例7: restore_triggers
def restore_triggers(self, tbl, triggers=None):
tbl = skytools.fq_name(tbl)
if tbl not in self.get_subscriber_table_list():
self.log.error("Table %s is not in the subscriber queue." % tbl)
sys.exit(1)
dst_db = self.get_database('subscriber_db')
dst_curs = dst_db.cursor()
if not triggers:
q = "select count(1) from londiste.subscriber_get_table_pending_triggers(%s)"
dst_curs.execute(q, [tbl])
if not dst_curs.fetchone()[0]:
self.log.info("No pending triggers found for %s." % tbl)
else:
q = "select londiste.subscriber_restore_all_table_triggers(%s)"
dst_curs.execute(q, [tbl])
else:
for trigger in triggers:
q = "select count(1) from londiste.find_table_triggers(%s) where trigger_name=%s"
dst_curs.execute(q, [tbl, trigger])
if dst_curs.fetchone()[0]:
self.log.info("Trigger %s on %s is already active." % (trigger, tbl))
continue
q = "select count(1) from londiste.subscriber_get_table_pending_triggers(%s) where trigger_name=%s"
dst_curs.execute(q, [tbl, trigger])
if not dst_curs.fetchone()[0]:
self.log.info("Trigger %s not found on %s" % (trigger, tbl))
continue
q = "select londiste.subscriber_restore_table_trigger(%s, %s)"
dst_curs.execute(q, [tbl, trigger])
dst_db.commit()
示例8: cmd_add_seq
def cmd_add_seq(self, *args):
"""Attach seqs(s) to local node."""
dst_db = self.get_database('db')
dst_curs = dst_db.cursor()
src_db = self.get_provider_db()
src_curs = src_db.cursor()
src_seqs = self.fetch_seqs(src_curs)
dst_seqs = self.fetch_seqs(dst_curs)
src_db.commit()
self.sync_seq_list(dst_curs, src_seqs, dst_seqs)
dst_db.commit()
args = self.expand_arg_list(dst_db, 'S', False, args)
# pick proper create flags
if self.options.create_full:
create_flags = skytools.T_SEQUENCE
elif self.options.create:
create_flags = skytools.T_SEQUENCE
else:
create_flags = 0
# seems ok
for seq in args:
seq = skytools.fq_name(seq)
self.add_seq(src_db, dst_db, seq, create_flags)
dst_db.commit()
示例9: cmd_add_table
def cmd_add_table(self, *args):
"""Attach table(s) to local node."""
dst_db = self.get_database('db')
dst_curs = dst_db.cursor()
src_db = self.get_provider_db()
src_curs = src_db.cursor()
src_tbls = self.fetch_set_tables(src_curs)
dst_tbls = self.fetch_set_tables(dst_curs)
src_db.commit()
self.sync_table_list(dst_curs, src_tbls, dst_tbls)
dst_db.commit()
# dont check for exist/not here (root handling)
problems = False
for tbl in args:
tbl = skytools.fq_name(tbl)
if (tbl in src_tbls) and not src_tbls[tbl]:
self.log.error("Table %s does not exist on provider, need to switch to different provider" % tbl)
problems = True
if problems:
self.log.error("Problems, canceling operation")
sys.exit(1)
# pick proper create flags
create = self.options.create_only
if not create and self.options.create:
create = 'full'
fmap = {
"full": skytools.T_ALL,
"pkey": skytools.T_PKEY,
}
create_flags = 0
if create:
for f in create.split(','):
if f not in fmap:
raise Exception("bad --create-only flag: " + f)
create_flags += fmap[f]
# seems ok
for tbl in args:
tbl = skytools.fq_name(tbl)
self.add_table(src_db, dst_db, tbl, create_flags)
示例10: work
def work(self):
"""Syncer main function."""
# 'SELECT 1' and COPY must use same snapshot, so change isolation level.
dst_db = self.get_database('db', isolation_level = skytools.I_REPEATABLE_READ)
provider_loc = self.get_provider_location(dst_db)
lock_db = self.get_database('lock_db', connstr = provider_loc)
setup_db = self.get_database('setup_db', autocommit = 1, connstr = provider_loc)
src_db = self.get_database('provider_db', connstr = provider_loc,
isolation_level = skytools.I_REPEATABLE_READ)
setup_curs = setup_db.cursor()
# provider node info
self.provider_node = self.get_provider_info(setup_curs)
src_tables, ignore = self.get_tables(src_db)
dst_tables, names = self.get_tables(dst_db)
if len(self.args) > 2:
tlist = self.args[2:]
else:
tlist = names
for tbl in tlist:
tbl = skytools.fq_name(tbl)
if not tbl in dst_tables:
self.log.warning('Table not subscribed: %s' % tbl)
continue
if not tbl in src_tables:
self.log.warning('Table not available on provider: %s' % tbl)
continue
t1 = src_tables[tbl]
t2 = dst_tables[tbl]
if t1.merge_state != 'ok':
self.log.warning('Table %s not ready yet on provider' % tbl)
continue
if t2.merge_state != 'ok':
self.log.warning('Table %s not synced yet, no point' % tbl)
continue
self.check_consumer(setup_db)
self.check_table(t1, t2, lock_db, src_db, dst_db, setup_db)
lock_db.commit()
src_db.commit()
dst_db.commit()
# signal caller about bad tables
sys.exit(self.bad_tables)
示例11: subscriber_remove_tables
def subscriber_remove_tables(self, table_list):
subscriber_tables = self.get_subscriber_table_list()
if not table_list and self.options.all:
table_list = ['*.*']
for tbl in table_list:
tbls = self.get_subscriber_table_list(skytools.fq_name(tbl))
for tbl in tbls:
if tbl in subscriber_tables:
self.log.info("Removing: %s" % tbl)
self.subscriber_remove_one_table(tbl)
else:
self.log.info("Table %s already removed" % tbl)
示例12: subscriber_add_tables
def subscriber_add_tables(self, table_list):
provider_tables = self.get_provider_table_list()
subscriber_tables = self.get_subscriber_table_list()
if not table_list and self.options.all:
table_list = ['*.*']
for tbl in provider_tables:
if tbl not in subscriber_tables:
table_list.append(tbl)
tbls = []
for tbl in table_list:
more = self.find_missing_subscriber_tables(skytools.fq_name(tbl))
if more == []:
self.log.info("No tables found that match %s" % tbl)
tbls.extend(more)
tbls = list(set(tbls))
err = 0
table_list = []
for tbl in tbls:
if tbl not in provider_tables:
err = 1
self.log.error("Table %s not attached to queue" % tbl)
if not self.options.force:
continue
table_list.append(tbl)
if err:
if self.options.force:
self.log.warning('--force used, ignoring errors')
err = self.check_tables(table_list)
if err:
if self.options.force:
self.log.warning('--force used, ignoring errors')
else:
sys.exit(1)
dst_db = self.get_database('subscriber_db')
dst_curs = dst_db.cursor()
for tbl in table_list:
if tbl in subscriber_tables:
self.log.info("Table %s already added" % tbl)
else:
self.log.info("Adding %s" % tbl)
self.subscriber_add_one_table(dst_curs, tbl)
dst_db.commit()
示例13: provider_remove_tables
def provider_remove_tables(self, table_list):
self.check_provider_queue()
cur_list = self.get_provider_table_list()
if not table_list and self.options.all:
table_list = cur_list
for tbl in table_list:
tbls = self.get_provider_table_list(skytools.fq_name(tbl))
for tbl in tbls:
if tbl not in cur_list:
self.log.info('%s already removed' % tbl)
else:
self.log.info("Removing %s" % tbl)
self.provider_remove_table(tbl)
self.provider_notify_change()
示例14: provider_add_tables
def provider_add_tables(self, table_list):
self.check_provider_queue()
if self.options.all and not table_list:
table_list = ['*.*']
cur_list = self.get_provider_table_list()
for tbl in table_list:
tbls = self.find_missing_provider_tables(skytools.fq_name(tbl))
for tbl in tbls:
if tbl not in cur_list:
self.log.info('Adding %s' % tbl)
self.provider_add_table(tbl)
else:
self.log.info("Table %s already added" % tbl)
self.provider_notify_change()
示例15: subscriber_remove_seq
def subscriber_remove_seq(self, seq_list):
dst_db = self.get_database('subscriber_db')
dst_curs = dst_db.cursor()
cur_list = self.get_subscriber_seq_list()
if not seq_list and self.options.all:
seq_list = cur_list
for seq in seq_list:
seq = skytools.fq_name(seq)
if seq not in cur_list:
self.log.warning('Seq %s not subscribed')
else:
self.log.info('Removing sequence: %s' % seq)
q = "select londiste.subscriber_remove_seq(%s, %s)"
dst_curs.execute(q, [self.pgq_queue_name, seq])
dst_db.commit()