Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB-12364: update zookeeper property if a core system table index is recreated(3.1) #5692

Open
wants to merge 1 commit into
base: branch-3.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
@SuppressFBWarnings(value="MS_PKGPROTECT")
public abstract class BaseDataDictionary implements DataDictionary, ModuleControl, ModuleSupportable,java.security.PrivilegedAction {
protected static final String CFG_SYSTABLES_ID = "SystablesIdentifier";
protected static final String CFG_SYSTABLES_INDEX1_ID = "SystablesIndex1Identifier";
public static final String CFG_SYSTABLES_INDEX1_ID = "SystablesIndex1Identifier";
protected static final String CFG_SYSTABLES_INDEX2_ID = "SystablesIndex2Identifier";
protected static final String CFG_SYSCOLUMNS_ID = "SyscolumnsIdentifier";
protected static final String CFG_SYSCOLUMNS_INDEX1_ID = "SyscolumnsIndex1Identifier";
Expand All @@ -56,7 +56,7 @@ public abstract class BaseDataDictionary implements DataDictionary, ModuleContro
protected static final String CFG_SYSSCHEMAS_INDEX1_ID = "SysschemasIndex1Identifier";
protected static final String CFG_SYSSCHEMAS_INDEX2_ID = "SysschemasIndex2Identifier";
protected static final int SYSCONGLOMERATES_CORE_NUM = 0;
protected static final int SYSTABLES_CORE_NUM = 1;
public static final int SYSTABLES_CORE_NUM = 1;
protected static final int SYSCOLUMNS_CORE_NUM = 2;
protected static final int SYSSCHEMAS_CORE_NUM = 3;
protected static final int NUM_CORE = 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ protected void loadDictionaryTables(TransactionController tc,
super.loadDictionaryTables(tc,startParams);

// Check splice data dictionary version to decide if upgrade is necessary
upgradeIfNecessary(tc);
upgradeIfNecessary(tc, startParams);

//upgrade may change SPLICE_DATA_DICTIONARY_VERSION
catalogVersion=(Splice_DD_Version)tc.getProperty(SPLICE_DATA_DICTIONARY_VERSION);
Expand Down Expand Up @@ -929,7 +929,7 @@ protected TabInfoImpl getPkTable() throws StandardException{
return pkTable;
}

private void upgradeIfNecessary(TransactionController tc) throws StandardException{
private void upgradeIfNecessary(TransactionController tc, Properties startParam) throws StandardException{

boolean toUpgrade = Boolean.TRUE.equals(EngineLifecycleService.toUpgrade.get());
// Only master can upgrade
Expand All @@ -940,7 +940,7 @@ private void upgradeIfNecessary(TransactionController tc) throws StandardExcepti
Splice_DD_Version catalogVersion=(Splice_DD_Version)tc.getProperty(SPLICE_DATA_DICTIONARY_VERSION);
if(needToUpgrade(catalogVersion)){
tc.elevate("dictionary");
SpliceCatalogUpgradeScripts scripts=new SpliceCatalogUpgradeScripts(this, tc);
SpliceCatalogUpgradeScripts scripts=new SpliceCatalogUpgradeScripts(this, tc, startParam);
scripts.runUpgrades(catalogVersion);
tc.setProperty(SPLICE_DATA_DICTIONARY_VERSION, spliceSoftwareVersion,true);
tc.commit();
Expand Down Expand Up @@ -2369,4 +2369,12 @@ private void insertIndex(TransactionController tc,
cd.getDescriptorName(), tabInfo.getTableName());
}
}

public void updateBootstrapProperty(Properties startParams, int catalogNum, String indexName, int indexId) {
if (catalogNum > NUM_CORE)
return;

startParams.put(indexName,Long.toString(
coreInfo[catalogNum].getIndexConglomerate(indexId)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,17 @@ public void addUpgradeScript(Splice_DD_Version version, int sprint, UpgradeScrip

static final public Splice_DD_Version baseVersion1 = new Splice_DD_Version(null, 2, 8, 0);
static final public Splice_DD_Version baseVersion2 = new Splice_DD_Version(null, 3, 1, 0);
static final public Splice_DD_Version baseVersion5 = new Splice_DD_Version(null, 3, 1, 1);
static final public Splice_DD_Version baseVersion3 = baseVersion2;
static final public Splice_DD_Version baseVersion4 = baseVersion2;

public SpliceCatalogUpgradeScripts(SpliceDataDictionary sdd, TransactionController tc){
public SpliceCatalogUpgradeScripts(SpliceDataDictionary sdd, TransactionController tc, Properties startParams){
this.sdd=sdd;
this.tc=tc;

scripts = new ArrayList<>();
addUpgradeScript(baseVersion4, 2020, new UpgradeAddConglomerateNumberIndex(sdd, tc));
addUpgradeScript(baseVersion4, 2024, new UpgradeScriptToPrioritizeSchemaIdInSystemIndices(sdd, tc));
addUpgradeScript(baseVersion5, 2020, new UpgradeAddConglomerateNumberIndex(sdd, tc));
addUpgradeScript(baseVersion5, 2024, new UpgradeScriptToPrioritizeSchemaIdInSystemIndices(sdd, tc, startParams));
// DB-11296: UpgradeConglomerateTable has to be executed first, because it adds a system table
// CONGLOMERATE_SI_TABLE_NAME that is from then on needed to create tables, e.g.
// in UpgradeScriptToAddSysNaturalNumbersTable. If UpgradeConglomerateTable is at the end,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@
import com.splicemachine.db.iapi.store.access.TransactionController;
import com.splicemachine.db.impl.sql.catalog.*;
import com.splicemachine.derby.impl.sql.catalog.SpliceDataDictionary;
import com.splicemachine.utils.SpliceLogUtils;

import java.util.Properties;

import static com.splicemachine.db.impl.sql.catalog.BaseDataDictionary.CFG_SYSTABLES_INDEX1_ID;

public class UpgradeScriptToPrioritizeSchemaIdInSystemIndices extends UpgradeScriptBase {
public UpgradeScriptToPrioritizeSchemaIdInSystemIndices(SpliceDataDictionary sdd, TransactionController tc) {

private Properties startParams;

public UpgradeScriptToPrioritizeSchemaIdInSystemIndices(SpliceDataDictionary sdd,
TransactionController tc,
Properties startParams) {
super(sdd, tc);
this.startParams = startParams;
}

@Override
Expand All @@ -35,6 +42,9 @@ protected void upgradeSystemTables() throws StandardException {
new int[]{SYSTABLESRowFactory.SYSTABLES_INDEX1_ID}
);

sdd.updateBootstrapProperty(startParams, BaseDataDictionary.SYSTABLES_CORE_NUM,
CFG_SYSTABLES_INDEX1_ID, SYSTABLESRowFactory.SYSTABLES_INDEX1_ID);

sdd.upgradeRecreateIndexesOfSystemTable(
tc,
DataDictionary.SYSTRIGGERS_CATALOG_NUM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public class SpliceCatalogUpgradeScriptsTest {
String s1 =
Expand Down Expand Up @@ -36,22 +37,23 @@ public class SpliceCatalogUpgradeScriptsTest {
"VERSION4.2023: com.splicemachine.derby.impl.sql.catalog.upgrade.UpgradeFixIndexDescriptors\n";

// Those scripts must run before other upgrade scripts
String s3 = "VERSION4.2020: com.splicemachine.derby.impl.sql.catalog.upgrade.UpgradeAddConglomerateNumberIndex\n" +
"VERSION4.2024: com.splicemachine.derby.impl.sql.catalog.upgrade.UpgradeScriptToPrioritizeSchemaIdInSystemIndices\n" +
String s3 = "VERSION5.2020: com.splicemachine.derby.impl.sql.catalog.upgrade.UpgradeAddConglomerateNumberIndex\n" +
"VERSION5.2024: com.splicemachine.derby.impl.sql.catalog.upgrade.UpgradeScriptToPrioritizeSchemaIdInSystemIndices\n" +
"VERSION4.1996: com.splicemachine.derby.impl.sql.catalog.upgrade.UpgradeConglomerateTable\n";
// add more scripts here

private String replaceVersions(String s) {
return s.replace("VERSION2", SpliceCatalogUpgradeScripts.baseVersion2.toString())
.replace("VERSION3", SpliceCatalogUpgradeScripts.baseVersion3.toString())
.replace("VERSION4", SpliceCatalogUpgradeScripts.baseVersion4.toString());
.replace("VERSION4", SpliceCatalogUpgradeScripts.baseVersion4.toString())
.replace("VERSION5", SpliceCatalogUpgradeScripts.baseVersion5.toString());
// add more base versions here.
}

@Test
public void test_since_1933()
{
SpliceCatalogUpgradeScripts s = new SpliceCatalogUpgradeScripts(null, null);
SpliceCatalogUpgradeScripts s = new SpliceCatalogUpgradeScripts(null, null, new Properties());
Splice_DD_Version version = new Splice_DD_Version(null, 3,1,0, 1933);
List<SpliceCatalogUpgradeScripts.VersionAndUpgrade> list =
SpliceCatalogUpgradeScripts.getScriptsToUpgrade(s.getScripts(), version);
Expand All @@ -61,7 +63,7 @@ public void test_since_1933()
@Test
public void test_since_1987()
{
SpliceCatalogUpgradeScripts s = new SpliceCatalogUpgradeScripts(null, null);
SpliceCatalogUpgradeScripts s = new SpliceCatalogUpgradeScripts(null, null, new Properties());
Splice_DD_Version version = new Splice_DD_Version(null, 3,1,0, 1987);
List<SpliceCatalogUpgradeScripts.VersionAndUpgrade> list =
SpliceCatalogUpgradeScripts.getScriptsToUpgrade(s.getScripts(), version);
Expand All @@ -71,7 +73,7 @@ public void test_since_1987()
@Test
public void test_since_2000_upgrade_empty()
{
SpliceCatalogUpgradeScripts s = new SpliceCatalogUpgradeScripts(null, null);
SpliceCatalogUpgradeScripts s = new SpliceCatalogUpgradeScripts(null, null, new Properties());
Splice_DD_Version version = new Splice_DD_Version(null, 4,0,0, 2000);
List<SpliceCatalogUpgradeScripts.VersionAndUpgrade> list =
SpliceCatalogUpgradeScripts.getScriptsToUpgrade(s.getScripts(), version);
Expand Down