new configuration parameters added to upgrade procedure
authorVictor Kirhenshtein <victor@netxms.org>
Fri, 20 Oct 2017 14:04:12 +0000 (17:04 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Fri, 20 Oct 2017 14:04:21 +0000 (17:04 +0300)
include/netxmsdb.h
src/server/tools/nxdbmgr/Makefile.am
src/server/tools/nxdbmgr/upgrade.cpp
src/server/tools/nxdbmgr/upgrade_v22.cpp [new file with mode: 0644]
src/server/tools/nxdbmgr/upgrade_v30.cpp

index 2320604..5c9dbe2 100644 (file)
@@ -25,9 +25,8 @@
 
 #define DB_LEGACY_SCHEMA_VERSION       700
 #define DB_SCHEMA_VERSION_MAJOR        30
-#define DB_SCHEMA_VERSION_MINOR        7
+#define DB_SCHEMA_VERSION_MINOR        8
 
-#define DB_SCHEMA_VERSION_V21_MINOR    4
 #define DB_SCHEMA_VERSION_V30_MINOR    DB_SCHEMA_VERSION_MINOR
 
 #endif
index 0da59f3..b38b2b9 100644 (file)
@@ -2,7 +2,7 @@ bin_PROGRAMS = nxdbmgr
 nxdbmgr_SOURCES = nxdbmgr.cpp check.cpp clear.cpp export.cpp import.cpp \
                   init.cpp migrate.cpp mm.cpp reindex.cpp resetadmin.cpp \
                   tables.cpp tdata_convert.cpp unlock.cpp upgrade.cpp \
-                 upgrade_v0.cpp upgrade_v21.cpp upgrade_v30.cpp
+                 upgrade_v0.cpp upgrade_v21.cpp upgrade_v22.cpp upgrade_v30.cpp
 nxdbmgr_CPPFLAGS=-I@top_srcdir@/include -I@top_srcdir@/src/server/include
 nxdbmgr_LDADD = ../../../libnetxms/libnetxms.la \
                 ../../../db/libnxdb/libnxdb.la \
index b6090e1..6d4bdbe 100644 (file)
@@ -28,6 +28,7 @@
  */
 bool MajorSchemaUpgrade_V0();
 bool MajorSchemaUpgrade_V21();
+bool MajorSchemaUpgrade_V22();
 bool MajorSchemaUpgrade_V30();
 
 /**
@@ -415,6 +416,7 @@ static struct
 {
    { 0, MajorSchemaUpgrade_V0 },
    { 21, MajorSchemaUpgrade_V21 },
+   { 22, MajorSchemaUpgrade_V22 },
    { 30, MajorSchemaUpgrade_V30 },
    { 0, NULL }
 };
diff --git a/src/server/tools/nxdbmgr/upgrade_v22.cpp b/src/server/tools/nxdbmgr/upgrade_v22.cpp
new file mode 100644 (file)
index 0000000..ff24a0d
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+** nxdbmgr - NetXMS database manager
+** Copyright (C) 2004-2017 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: upgrade_v22.cpp
+**
+**/
+
+#include "nxdbmgr.h"
+
+/**
+ * Upgrade from 22.1 to 30.0
+ */
+static bool H_UpgradeFromV1()
+{
+   CHK_EXEC(SetMajorSchemaVersion(22, 0));
+   return true;
+}
+
+/**
+ * Upgrade map
+ */
+static struct
+{
+   int version;
+   int nextMajor;
+   int nextMinor;
+   bool (* upgradeProc)();
+} s_dbUpgradeMap[] =
+{
+   { 1, 30, 0, H_UpgradeFromV1 },
+   { 0, 0, 0, NULL }
+};
+
+/**
+ * Upgrade database to new version
+ */
+bool MajorSchemaUpgrade_V22()
+{
+   INT32 major, minor;
+   if (!DBGetSchemaVersion(g_hCoreDB, &major, &minor))
+      return false;
+
+   while(major == 21)
+   {
+      // Find upgrade procedure
+      int i;
+      for(i = 0; s_dbUpgradeMap[i].upgradeProc != NULL; i++)
+         if (s_dbUpgradeMap[i].version == minor)
+            break;
+      if (s_dbUpgradeMap[i].upgradeProc == NULL)
+      {
+         _tprintf(_T("Unable to find upgrade procedure for version 22.%d\n"), minor);
+         return false;
+      }
+      _tprintf(_T("Upgrading from version 22.%d to %d.%d\n"), minor, s_dbUpgradeMap[i].nextMajor, s_dbUpgradeMap[i].nextMinor);
+      DBBegin(g_hCoreDB);
+      if (s_dbUpgradeMap[i].upgradeProc())
+      {
+         DBCommit(g_hCoreDB);
+         if (!DBGetSchemaVersion(g_hCoreDB, &major, &minor))
+            return false;
+      }
+      else
+      {
+         _tprintf(_T("Rolling back last stage due to upgrade errors...\n"));
+         DBRollback(g_hCoreDB);
+         return false;
+      }
+   }
+   return true;
+}
index 76d1a42..07df456 100644 (file)
 #include "nxdbmgr.h"
 
 /**
+ * Upgrade from 30.7 to 30.8 (changes also included into 22.1)
+ */
+static bool H_UpgradeFromV7()
+{
+   if (GetSchemaLevelForMajorVersion(22) < 1)
+   {
+      CHK_EXEC(CreateConfigParam(_T("DataCollector.ThreadPool.BaseSize"), _T("10"), _T("Base size for data collector thread pool."), 'I', true, true, false, false));
+      CHK_EXEC(CreateConfigParam(_T("DataCollector.ThreadPool.MaxSize"), _T("250"), _T("Maximum size for data collector thread pool."), 'I', true, true, false, false));
+   }
+   CHK_EXEC(SetMinorSchemaVersion(8));
+   return true;
+}
+
+/**
  * Upgrade from 30.6 to 30.7 (changes also included into 21.4)
  */
 static bool H_UpgradeFromV6()
@@ -466,6 +480,7 @@ static struct
    bool (* upgradeProc)();
 } s_dbUpgradeMap[] =
 {
+   { 7, 30, 8, H_UpgradeFromV7 },
    { 6, 30, 7, H_UpgradeFromV6 },
    { 5, 30, 6, H_UpgradeFromV5 },
    { 4, 30, 5, H_UpgradeFromV4 },