Fix upgrade so repository upgrade will succeed

Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/a49afa1b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/a49afa1b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/a49afa1b

Branch: refs/heads/master
Commit: a49afa1be39fed8b90efe15d66024548123075d9
Parents: ff89586
Author: Dave Birdsall <[email protected]>
Authored: Wed Jul 6 18:30:46 2016 +0000
Committer: Dave Birdsall <[email protected]>
Committed: Wed Jul 6 18:30:46 2016 +0000

----------------------------------------------------------------------
 core/sql/optimizer/RelExeUtil.h           |  7 +++++
 core/sql/parser/ParKeyWords.cpp           |  1 +
 core/sql/parser/sqlparser.y               | 41 +++++++++++++++++++-------
 core/sql/sqlcomp/CmpSeabaseDDL.h          |  2 +-
 core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp  | 27 ++++++++++-------
 core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp | 16 +++++-----
 core/sql/sqlcomp/CmpSeabaseDDLupgrade.h   | 23 +++++++++++++--
 7 files changed, 85 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a49afa1b/core/sql/optimizer/RelExeUtil.h
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/RelExeUtil.h b/core/sql/optimizer/RelExeUtil.h
index b97cf72..2591926 100644
--- a/core/sql/optimizer/RelExeUtil.h
+++ b/core/sql/optimizer/RelExeUtil.h
@@ -242,6 +242,7 @@ public:
     dropAuthorization_(FALSE),
     addSeqTable_(FALSE),
     addSchemaObjects_(FALSE),
+    minimal_(FALSE),
     returnStatus_(FALSE),
     flags_(0)
   {
@@ -255,6 +256,7 @@ public:
         NABoolean createMDviews, NABoolean dropMDviews,
          NABoolean initAuthorization, NABoolean dropAuthorization,
         NABoolean addSeqTable, NABoolean updateVersion, NABoolean 
addSchemaObjects,
+         NABoolean minimal,
         char * ddlStmtText,
         CharInfo::CharSet ddlStmtTextCharSet,
          CollHeap *oHeap = CmpCommon::statementHeap())
@@ -280,6 +282,7 @@ public:
     dropAuthorization_(dropAuthorization),
     addSeqTable_(addSeqTable),
     addSchemaObjects_(addSchemaObjects),
+    minimal_(minimal),
     returnStatus_(FALSE),
     flags_(0)
   {
@@ -318,6 +321,7 @@ public:
     dropAuthorization_(FALSE),
     addSeqTable_(FALSE),
     addSchemaObjects_(FALSE),
+    minimal_(FALSE),
     returnStatus_(FALSE),
     flags_(0)
   {
@@ -390,6 +394,7 @@ public:
   NABoolean dropAuthorization() { return dropAuthorization_; }
   NABoolean addSeqTable() { return addSeqTable_; }
   NABoolean addSchemaObjects() { return addSchemaObjects_; }
+  NABoolean minimal() { return minimal_; }
 
   short ddlXnsInfo(NABoolean &ddlXns, NABoolean &xnCanBeStarted);
 
@@ -489,6 +494,8 @@ public:
   NABoolean dropAuthorization_;
   NABoolean addSeqTable_;
   NABoolean addSchemaObjects_;
+  NABoolean minimal_;  // meaningful only when initHbase_ is true; if this is 
true,
+                       // means create the metadata tables only (and not 
repository etc.)
 
   // if set, this ddl cannot run under a user transaction. It must run in 
autocommit
   // mode.

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a49afa1b/core/sql/parser/ParKeyWords.cpp
----------------------------------------------------------------------
diff --git a/core/sql/parser/ParKeyWords.cpp b/core/sql/parser/ParKeyWords.cpp
index fee890f..c75cae8 100644
--- a/core/sql/parser/ParKeyWords.cpp
+++ b/core/sql/parser/ParKeyWords.cpp
@@ -637,6 +637,7 @@ ParKeyWord ParKeyWords::keyWords_[] = {
   ParKeyWord("MESSAGE_TEXT",       TOK_MESSAGE_TEXT, NONRESTOKEN_),
   ParKeyWord("METADATA",       TOK_METADATA, SECOND_ | NONRESTOKEN_),
   ParKeyWord("MIN",                TOK_MIN,         
ANS_|RESWORD_|NONRESTOKEN_),
+  ParKeyWord("MINIMAL",            TOK_MINIMAL,     NONRESTOKEN_),
   ParKeyWord("MINUTE",             TOK_MINUTE,      ANS_|RESWORD_|MPWORD_),
   ParKeyWord("MINUTES",            TOK_MINUTES,     NONRESTOKEN_),
   ParKeyWord("MINVALUE",           TOK_MINVALUE,   NONRESTOKEN_),

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a49afa1b/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index 318988b..6cc4040 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -831,6 +831,7 @@ static void enableMakeQuotedStringISO88591Mechanism()
 %token <tokval> TOK_MERGE
 %token <tokval> TOK_METADATA
 %token <tokval> TOK_MIN
+%token <tokval> TOK_MINIMAL
 %token <tokval> TOK_MINUTE
 %token <tokval> TOK_MINUTES
 %token <tokval> TOK_MINVALUE
@@ -16022,13 +16023,30 @@ exe_util_init_hbase : TOK_INITIALIZE TOK_TRAFODION
 
                 DDLExpr * de = new(PARSERHEAP()) DDLExpr(TRUE, FALSE, TRUE, 
FALSE,
                                                           FALSE, FALSE,
-                                                         FALSE, FALSE, FALSE,
+                                                         FALSE, FALSE, FALSE, 
FALSE,
                                                          (char*)stmt->data(),
                                                          stmtCharSet,
                                                          PARSERHEAP());
 
                 $$ = de;
-              } 
+              }
+
+           | TOK_INITIALIZE TOK_TRAFODION ',' TOK_MINIMAL
+               {
+                CharInfo::CharSet stmtCharSet = CharInfo::UnknownCharSet;
+                NAString * stmt = getSqlStmtStr ( stmtCharSet  // out - 
CharInfo::CharSet &
+                                                  , PARSERHEAP() 
+                                              );
+
+                DDLExpr * de = new(PARSERHEAP()) DDLExpr(TRUE, FALSE, TRUE, 
FALSE,
+                                                          FALSE, FALSE,
+                                                         FALSE, FALSE, FALSE, 
TRUE /* minimal */,
+                                                         (char*)stmt->data(),
+                                                         stmtCharSet,
+                                                         PARSERHEAP());
+
+                $$ = de;                
+               }
 
            | TOK_INITIALIZE TOK_TRAFODION ',' TOK_NO TOK_METADATA TOK_VIEWS
                {
@@ -16039,7 +16057,7 @@ exe_util_init_hbase : TOK_INITIALIZE TOK_TRAFODION
 
                 DDLExpr * de = new(PARSERHEAP()) DDLExpr(TRUE, FALSE, FALSE, 
FALSE,
                                                           FALSE, FALSE,
-                                                         FALSE, FALSE, FALSE,
+                                                         FALSE, FALSE, FALSE, 
FALSE,
                                                          (char*)stmt->data(),
                                                          stmtCharSet,
                                                          PARSERHEAP());
@@ -16056,7 +16074,7 @@ exe_util_init_hbase : TOK_INITIALIZE TOK_TRAFODION
 
                 DDLExpr * de = new(PARSERHEAP()) DDLExpr(FALSE, TRUE, FALSE, 
TRUE,
                                                           FALSE, FALSE,
-                                                         FALSE, FALSE, FALSE,
+                                                         FALSE, FALSE, FALSE, 
FALSE,
                                                          (char*)stmt->data(),
                                                          stmtCharSet,
                                                          PARSERHEAP());
@@ -16073,7 +16091,7 @@ exe_util_init_hbase : TOK_INITIALIZE TOK_TRAFODION
 
                 DDLExpr * de = new(PARSERHEAP()) DDLExpr(FALSE, FALSE, TRUE, 
FALSE,
                                                           FALSE, FALSE,
-                                                         FALSE, FALSE, FALSE,
+                                                         FALSE, FALSE, FALSE, 
FALSE,
                                                          (char*)stmt->data(),
                                                          stmtCharSet,
                                                          PARSERHEAP());
@@ -16090,7 +16108,7 @@ exe_util_init_hbase : TOK_INITIALIZE TOK_TRAFODION
 
                 DDLExpr * de = new(PARSERHEAP()) DDLExpr(FALSE, FALSE, FALSE, 
TRUE,
                                                           FALSE, FALSE,
-                                                         FALSE, FALSE, FALSE,
+                                                         FALSE, FALSE, FALSE, 
FALSE,
                                                          (char*)stmt->data(),
                                                          stmtCharSet,
                                                          PARSERHEAP());
@@ -16114,7 +16132,7 @@ exe_util_init_hbase : TOK_INITIALIZE TOK_TRAFODION
 
                 DDLExpr * de = new(PARSERHEAP()) DDLExpr(FALSE, FALSE, FALSE, 
FALSE,
                                                           FALSE, FALSE,
-                                                         TRUE, FALSE, FALSE,
+                                                         TRUE, FALSE, FALSE, 
FALSE,
                                                          (char*)stmt->data(),
                                                          stmtCharSet,
                                                          PARSERHEAP());
@@ -16131,7 +16149,7 @@ exe_util_init_hbase : TOK_INITIALIZE TOK_TRAFODION
 
                 DDLExpr * de = new(PARSERHEAP()) DDLExpr(FALSE, FALSE, FALSE, 
FALSE,
                                                           FALSE, FALSE,
-                                                         FALSE, FALSE, TRUE,
+                                                         FALSE, FALSE, TRUE, 
FALSE,
                                                          (char*)stmt->data(),
                                                          stmtCharSet,
                                                          PARSERHEAP());
@@ -16247,7 +16265,7 @@ exe_util_init_hbase : TOK_INITIALIZE TOK_TRAFODION
                                               );
                 DDLExpr * ia = new(PARSERHEAP()) DDLExpr(FALSE, FALSE, FALSE, 
FALSE,
                                                           TRUE, FALSE,
-                                                         FALSE, FALSE, FALSE,
+                                                         FALSE, FALSE, FALSE, 
FALSE,
                                                          (char*)stmt->data(),
                                                          stmtCharSet,
                                                          PARSERHEAP());
@@ -16280,7 +16298,7 @@ exe_util_init_hbase : TOK_INITIALIZE TOK_TRAFODION
 
                 DDLExpr * ia = new(PARSERHEAP()) DDLExpr(FALSE, FALSE, FALSE, 
FALSE,
                                                           FALSE, TRUE,
-                                                         FALSE, FALSE, FALSE,
+                                                         FALSE, FALSE, FALSE, 
FALSE,
                                                          (char*)stmt->data(),
                                                          stmtCharSet,
                                                          PARSERHEAP());
@@ -16298,7 +16316,7 @@ exe_util_init_hbase : TOK_INITIALIZE TOK_TRAFODION
 
                 DDLExpr * de = new(PARSERHEAP()) DDLExpr(FALSE, FALSE, FALSE, 
FALSE,
                                                           FALSE, FALSE,
-                                                         FALSE, TRUE, FALSE,
+                                                         FALSE, TRUE, FALSE, 
FALSE,
                                                          (char*)stmt->data(),
                                                          stmtCharSet,
                                                          PARSERHEAP());
@@ -33054,6 +33072,7 @@ nonreserved_word :      TOK_ABORT
                       | TOK_MESSAGE_OCTET_LEN
                       | TOK_MESSAGE_TEXT
                       | TOK_METADATA
+                      | TOK_MINIMAL
                      | TOK_MINUTES
                      | TOK_MINVALUE
                       | TOK_MODE

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a49afa1b/core/sql/sqlcomp/CmpSeabaseDDL.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDL.h b/core/sql/sqlcomp/CmpSeabaseDDL.h
index 970a6cf..21f5cbe 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDL.h
+++ b/core/sql/sqlcomp/CmpSeabaseDDL.h
@@ -1243,7 +1243,7 @@ protected:
                             StmtDDLDropHbaseTable                  * 
createTableNode,
                             NAString &currCatName, NAString &currSchName);
   
-  void initSeabaseMD(NABoolean ddlXns);
+  void initSeabaseMD(NABoolean ddlXns, NABoolean minimal);
   void dropSeabaseMD(NABoolean ddlXns);
   void createSeabaseMDviews();
   void dropSeabaseMDviews();

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a49afa1b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp 
b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
index d65a5cc..e91c810 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
@@ -6730,7 +6730,7 @@ short CmpSeabaseDDL::updateSeabaseAuths(
   return 0;
 }
 
-void CmpSeabaseDDL::initSeabaseMD(NABoolean ddlXns)
+void CmpSeabaseDDL::initSeabaseMD(NABoolean ddlXns, NABoolean minimal)
 {
   int breadCrumb = -1;  // useful for debugging
   Lng32 retcode = 0;
@@ -6975,16 +6975,23 @@ void CmpSeabaseDDL::initSeabaseMD(NABoolean ddlXns)
       goto label_error;
     }
 
- if (createRepos(&cliInterface))
+ // If this is a MINIMAL initialization, don't create the repository
+ // or privilege manager tables. (This happens underneath an upgrade,
+ // for example, because the repository and privilege manager tables
+ // already exist and we will later upgrade them.)
+ if (!minimal)  
    {
-     breadCrumb = 10;
-     goto label_error;
-   }
+     if (createRepos(&cliInterface))
+       {
+         breadCrumb = 10;
+         goto label_error;
+       }
 
- if (createPrivMgrRepos(&cliInterface, ddlXns))
-   {
-     breadCrumb = 11;
-     goto label_error;
+     if (createPrivMgrRepos(&cliInterface, ddlXns))
+       {
+         breadCrumb = 11;
+         goto label_error;
+       }
    }
 
  if (createSeabaseLibmgr (&cliInterface))
@@ -8557,7 +8564,7 @@ short CmpSeabaseDDL::executeSeabaseDDL(DDLExpr * ddlExpr, 
ExprNode * ddlNode,
 
   if (ddlExpr->initHbase()) 
     {
-      initSeabaseMD(ddlExpr->ddlXns());
+      initSeabaseMD(ddlExpr->ddlXns(), ddlExpr->minimal());
     }
   else if (ddlExpr->dropHbase())
     {

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a49afa1b/core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp 
b/core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp
index e6e4caa..1c058df 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLupgrade.cpp
@@ -170,13 +170,7 @@ short CmpSeabaseMDupgrade::dropMDtables(ExpHbaseInterface 
*ehi,
       
     } // for
   
-  Lng32 reposErrcode = dropReposTables(ehi, oldTbls);
-  if (errcode)
-    return errcode;
-  else if (reposErrcode)
-    return reposErrcode;
-  else
-    return 0;
+  return errcode;
 }
 
 short CmpSeabaseMDupgrade::restoreOldMDtables(ExpHbaseInterface *ehi)
@@ -322,6 +316,9 @@ short 
CmpSeabaseMDupgrade::executeSeabaseMDupgrade(CmpDDLwithStatusInfo *mdui,
 
   while (1)
     {
+      // TODO: remove this debugging code
+      cout << "mdui->step() is " << mdui->step() << ", mdui->subStep() is " << 
mdui->subStep() << endl;
+      // TODO: remove the above debugging code
       switch (mdui->step())
        {
        case UPGRADE_START: 
@@ -979,7 +976,10 @@ short 
CmpSeabaseMDupgrade::executeSeabaseMDupgrade(CmpDDLwithStatusInfo *mdui,
                  CmpCommon::context()->setIsUninitializedSeabase(TRUE);
                  CmpCommon::context()->uninitializedSeabaseErrNum() = -1393; 
// MD doesn't exist
 
-                 str_sprintf(buf, "initialize trafodion;");
+                  // Use "initialize trafodion, minimal" so we only create the 
metadata
+                  // tables. The other tables (repository and privilege 
manager) already
+                  // exist; we will upgrade them later in this method.
+                 str_sprintf(buf, "initialize trafodion, minimal;");
                  
                  cliRC = cliInterface.executeImmediate(buf);
                  if (cliRC < 0)

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a49afa1b/core/sql/sqlcomp/CmpSeabaseDDLupgrade.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLupgrade.h 
b/core/sql/sqlcomp/CmpSeabaseDDLupgrade.h
index 4e7111c..3fcc94b 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLupgrade.h
+++ b/core/sql/sqlcomp/CmpSeabaseDDLupgrade.h
@@ -89,7 +89,12 @@ struct MDUpgradeInfo
 
   // if new and old col info is different, then data need to be copied using
   // explicit column names in insert and select part of the query.
-  // insert into tgt (insertedCols) select selectedCols from src;
+  // upsert into tgt (insertedCols) select selectedCols from src;
+  // Note that the OBJECTS table must always do this, since we need to modify
+  // the table name for rows concerning the metadata tables themselves. That 
is,
+  // we are copying in rows concerning the *old* metadata tables; rows 
concerning
+  // the *new* metadata tables are already there from "initialize trafodion" 
and
+  // we don't want to overwrite them as part of the UPSERT.
   const char * insertedCols;
   const char * selectedCols;
 
@@ -191,7 +196,21 @@ static const MDUpgradeInfo allMDupgradeInfo[] = {
    seabaseObjectsDDL, sizeof(seabaseObjectsDDL),
    NULL, 0,
    NULL, 0,
-   FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
+   FALSE,
+   // Note: For OBJECTS, we always have to provide insertedCols and
+   // selectedCols since we have to modify the table name for rows
+   // concerning the old metadata (see the "case" expression below).
+   "catalog_name,schema_name,"
+   "object_name,"
+   "object_type,object_uid,"
+   "create_time,redef_time,valid_def,droppable,object_owner,schema_owner,"
+   "flags",
+   "catalog_name,schema_name,"
+   "case when schema_name = '_MD_' then object_name || '_OLD_MD' else 
object_name end,"
+   "object_type,object_uid,"
+   "create_time,redef_time,valid_def,droppable,object_owner,schema_owner,"
+   "flags",
+   NULL, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
 
   {SEABASE_OBJECTS_UNIQ_IDX, SEABASE_OBJECTS_UNIQ_IDX_OLD_MD,
    seabaseObjectsUniqIdxDDL, sizeof(seabaseObjectsUniqIdxDDL),

Reply via email to