configuration parameter DBWriter.MaxRecordsPerTransaction added to database
[public/netxms.git] / src / server / tools / nxdbmgr / upgrade_v22.cpp
1 /*
2 ** nxdbmgr - NetXMS database manager
3 ** Copyright (C) 2004-2017 Victor Kirhenshtein
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 **
19 ** File: upgrade_v22.cpp
20 **
21 **/
22
23 #include "nxdbmgr.h"
24
25 /**
26 * Upgrade from 22.2 to 30.0
27 */
28 static bool H_UpgradeFromV2()
29 {
30 CHK_EXEC(SetMajorSchemaVersion(30, 0));
31 return true;
32 }
33
34 /**
35 * Upgrade from 22.1 to 22.2
36 */
37 static bool H_UpgradeFromV1()
38 {
39 CHK_EXEC(CreateConfigParam(_T("DBWriter.MaxRecordsPerTransaction"), _T("1000"), _T("Maximum number of records per one transaction for delayed database writes."), 'I', true, true, false, false));
40 CHK_EXEC(SetMinorSchemaVersion(2));
41 return true;
42 }
43
44 /**
45 * Upgrade from 22.0 to 22.1
46 */
47 static bool H_UpgradeFromV0()
48 {
49 int count = ConfigReadInt(_T("NumberOfDataCollectors"), 250);
50 TCHAR value[64];
51 _sntprintf(value, 64,_T("%d"), std::max(250, count));
52 CHK_EXEC(CreateConfigParam(_T("DataCollector.ThreadPool.BaseSize"), _T("10"), _T("Base size for data collector thread pool."), 'I', true, true, false, false));
53 CHK_EXEC(CreateConfigParam(_T("DataCollector.ThreadPool.MaxSize"), value, _T("Maximum size for data collector thread pool."), 'I', true, true, false, false));
54 CHK_EXEC(SQLQuery(_T("UPDATE config SET default_value='250' WHERE var_name='DataCollector.ThreadPool.MaxSize'")));
55 CHK_EXEC(SQLQuery(_T("DELETE FROM config WHERE var_name='NumberOfDataCollectors'")));
56 CHK_EXEC(SetMinorSchemaVersion(1));
57 return true;
58 }
59
60 /**
61 * Upgrade map
62 */
63 static struct
64 {
65 int version;
66 int nextMajor;
67 int nextMinor;
68 bool (* upgradeProc)();
69 } s_dbUpgradeMap[] =
70 {
71 { 2, 30, 0, H_UpgradeFromV2 },
72 { 1, 22, 2, H_UpgradeFromV1 },
73 { 0, 22, 1, H_UpgradeFromV0 },
74 { 0, 0, 0, NULL }
75 };
76
77 /**
78 * Upgrade database to new version
79 */
80 bool MajorSchemaUpgrade_V22()
81 {
82 INT32 major, minor;
83 if (!DBGetSchemaVersion(g_hCoreDB, &major, &minor))
84 return false;
85
86 while(major == 22)
87 {
88 // Find upgrade procedure
89 int i;
90 for(i = 0; s_dbUpgradeMap[i].upgradeProc != NULL; i++)
91 if (s_dbUpgradeMap[i].version == minor)
92 break;
93 if (s_dbUpgradeMap[i].upgradeProc == NULL)
94 {
95 _tprintf(_T("Unable to find upgrade procedure for version 22.%d\n"), minor);
96 return false;
97 }
98 _tprintf(_T("Upgrading from version 22.%d to %d.%d\n"), minor, s_dbUpgradeMap[i].nextMajor, s_dbUpgradeMap[i].nextMinor);
99 DBBegin(g_hCoreDB);
100 if (s_dbUpgradeMap[i].upgradeProc())
101 {
102 DBCommit(g_hCoreDB);
103 if (!DBGetSchemaVersion(g_hCoreDB, &major, &minor))
104 return false;
105 }
106 else
107 {
108 _tprintf(_T("Rolling back last stage due to upgrade errors...\n"));
109 DBRollback(g_hCoreDB);
110 return false;
111 }
112 }
113 return true;
114 }