From 308f0c8c709c41cb12a4fe00cc9c3e7db7d41981 Mon Sep 17 00:00:00 2001 From: water32 Date: Mon, 18 Apr 2016 23:00:03 +0800 Subject: [PATCH] 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. --- gpMgmt/bin/gppylib/gparray.py | 41 ++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/gpMgmt/bin/gppylib/gparray.py b/gpMgmt/bin/gppylib/gparray.py index c20396f3d9..586b3cab75 100755 --- a/gpMgmt/bin/gppylib/gparray.py +++ b/gpMgmt/bin/gppylib/gparray.py @@ -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: -- GitLab