提交 308f0c8c 编写于 作者: W water32 提交者: Yandong Yao

Update gparray.py

Old code query instance's database data directory, one query per instance.
This will generate many logs to log file, example: gpstate
New code, query all data about database's data directory, map date to key -> array, then set to segments object.
So use one query replace many query avoid many times query in database.
上级 4229f800
......@@ -1446,28 +1446,29 @@ class GpArray:
hostname, address, port, fslocation, replicationPort)
segments.append(seg)
datcatloc = dbconn.execSQL(conn, '''
select fsloc.dbid, fsloc.fselocation || '/' ||
case when db.dattablespace = 1663
then 'base'
else db.dattablespace::text
end || '/'||db.oid as catloc
from pg_Database db, pg_tablespace ts,
(SELECT dbid, fs.oid, fselocation
FROM pg_catalog.gp_segment_configuration
JOIN pg_catalog.pg_filespace_entry on (dbid = fsedbid)
JOIN pg_catalog.pg_filespace fs on (fsefsoid = fs.oid)) fsloc
where db.dattablespace = ts.oid
and ts.spcfsoid = fsloc.oid''')
conn.close()
catlocmap = {}
for row in datcatloc:
if catlocmap.has_key(row[0]):
catlocmap[row[0]].append(row[1])
else:
catlocmap[row[0]] = [row[1]]
for seg in segments:
datcatloc = dbconn.execSQL(conn, '''
select fsloc.fselocation || '/' ||
case when db.dattablespace = 1663
then 'base'
else db.dattablespace::text
end || '/'||db.oid as catloc
from pg_Database db, pg_tablespace ts,
(SELECT dbid, fs.oid, fselocation
FROM pg_catalog.gp_segment_configuration
JOIN pg_catalog.pg_filespace_entry on (dbid = fsedbid)
JOIN pg_catalog.pg_filespace fs on (fsefsoid = fs.oid)) fsloc
where db.dattablespace = ts.oid
and ts.spcfsoid = fsloc.oid
and fsloc.dbid = %d
''' % seg.dbid)
seg.catdirs = []
for row in datcatloc:
seg.catdirs.append(row[0])
seg.catdirs = catlocmap[seg.dbid]
conn.close()
origSegments = [seg.copy() for seg in segments]
if strategy_rows.rowcount == 0:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册