use of org.voltdb.catalog.Database in project voltdb by VoltDB.
the class ExportManager method updateCatalog.
public synchronized void updateCatalog(CatalogContext catalogContext, boolean requireCatalogDiffCmdsApplyToEE, boolean requiresNewExportGeneration, List<Integer> partitions) {
final Cluster cluster = catalogContext.catalog.getClusters().get("cluster");
final Database db = cluster.getDatabases().get("database");
final CatalogMap<Connector> connectors = db.getConnectors();
updateProcessorConfig(connectors);
if (m_processorConfig.isEmpty()) {
m_lastNonEnabledGeneration = catalogContext.m_uniqueId;
return;
}
if (!requiresNewExportGeneration) {
exportLog.info("Skipped rolling generations as no stream related changes happened during this update.");
return;
}
/**
* This checks if the catalogUpdate was done in EE or not. If catalog update is skipped for @UpdateClasses and such
* EE does not roll to new generation and thus we need to ignore creating new generation roll with the current generation.
* If anything changes in getDiffCommandsForEE or design changes pay attention to fix this.
*/
if (requireCatalogDiffCmdsApplyToEE == false) {
exportLog.info("Skipped rolling generations as generation not created in EE.");
return;
}
File exportOverflowDirectory = new File(VoltDB.instance().getExportOverflowPath());
ExportGeneration newGeneration;
try {
newGeneration = new ExportGeneration(catalogContext.m_uniqueId, exportOverflowDirectory, false);
newGeneration.setGenerationDrainRunnable(new GenerationDrainRunnable(newGeneration));
newGeneration.initializeGenerationFromCatalog(connectors, m_hostId, m_messenger, partitions);
m_generations.put(catalogContext.m_uniqueId, newGeneration);
} catch (IOException e1) {
VoltDB.crashLocalVoltDB("Error processing catalog update in export system", true, e1);
}
/*
* If there is no existing export processor, create an initial one.
* This occurs when export is turned on/off at runtime.
*/
if (m_processor.get() == null) {
exportLog.info("First stream created processor will be initialized: " + m_loaderClass);
createInitialExportProcessor(catalogContext, connectors, false, partitions, false);
}
}
use of org.voltdb.catalog.Database in project voltdb by VoltDB.
the class CatalogUtil method setUsersInfo.
/**
* Set user info in the catalog.
* @param catalog The catalog to be updated.
* @param users A reference to the <users> element of the deployment.xml file.
* @throws RuntimeException when there is an user with invalid masked password.
*/
private static void setUsersInfo(Catalog catalog, UsersType users) throws RuntimeException {
if (users == null) {
return;
}
// The database name is not available in deployment.xml (it is defined
// in project.xml). However, it must always be named "database", so
// I've temporarily hardcoded it here until a more robust solution is
// available.
Database db = catalog.getClusters().get("cluster").getDatabases().get("database");
SecureRandom sr = new SecureRandom();
for (UsersType.User user : users.getUser()) {
Set<String> roles = extractUserRoles(user);
String sha1hex = user.getPassword();
String sha256hex = user.getPassword();
if (user.isPlaintext()) {
sha1hex = extractPassword(user.getPassword(), ClientAuthScheme.HASH_SHA1);
sha256hex = extractPassword(user.getPassword(), ClientAuthScheme.HASH_SHA256);
} else if (user.getPassword().length() == 104) {
int sha1len = ClientAuthScheme.getHexencodedDigestLength(ClientAuthScheme.HASH_SHA1);
sha1hex = sha1hex.substring(0, sha1len);
sha256hex = sha256hex.substring(sha1len);
} else {
// if one user has invalid password, give a warn.
hostLog.warn("User \"" + user.getName() + "\" has invalid masked password in deployment file.");
// throw exception disable user with invalid masked password
throw new RuntimeException("User \"" + user.getName() + "\" has invalid masked password in deployment file");
}
org.voltdb.catalog.User catUser = db.getUsers().add(user.getName());
// generate salt only once for sha1 and sha256
String saltGen = BCrypt.gensalt(BCrypt.GENSALT_DEFAULT_LOG2_ROUNDS, sr);
String hashedPW = BCrypt.hashpw(sha1hex, saltGen);
String hashedPW256 = BCrypt.hashpw(sha256hex, saltGen);
catUser.setShadowpassword(hashedPW);
catUser.setSha256shadowpassword(hashedPW256);
// process the @groups and @roles comma separated list
for (final String role : roles) {
final Group catalogGroup = db.getGroups().get(role);
// if the role doesn't exist, ignore it.
if (catalogGroup != null) {
final GroupRef groupRef = catUser.getGroups().add(role);
groupRef.setGroup(catalogGroup);
} else {
hostLog.warn("User \"" + user.getName() + "\" is assigned to non-existent role \"" + role + "\" " + "and may not have the expected database permissions.");
}
}
}
}
use of org.voltdb.catalog.Database in project voltdb by VoltDB.
the class CatalogUtil method setDrInfo.
private static void setDrInfo(Catalog catalog, DrType dr, ClusterType clusterType) {
int clusterId;
Cluster cluster = catalog.getClusters().get("cluster");
final Database db = cluster.getDatabases().get("database");
assert cluster != null;
if (dr != null) {
ConnectionType drConnection = dr.getConnection();
cluster.setDrproducerenabled(dr.isListen());
cluster.setDrproducerport(dr.getPort());
cluster.setDrrole(dr.getRole().name().toLowerCase());
if (dr.getRole() == DrRoleType.XDCR) {
// Setting this for compatibility mode only, don't use in new code
db.setIsactiveactivedred(true);
}
// Backward compatibility to support cluster id in DR tag
if (clusterType.getId() == null && dr.getId() != null) {
clusterId = dr.getId();
} else if (clusterType.getId() != null && dr.getId() == null) {
clusterId = clusterType.getId();
} else if (clusterType.getId() == null && dr.getId() == null) {
clusterId = 0;
} else {
if (clusterType.getId() == dr.getId()) {
clusterId = clusterType.getId();
} else {
throw new RuntimeException("Detected two conflicting cluster ids in deployement file, setting cluster id in DR tag is " + "deprecated, please remove");
}
}
cluster.setDrflushinterval(dr.getFlushInterval());
if (drConnection != null) {
String drSource = drConnection.getSource();
cluster.setDrmasterhost(drSource);
cluster.setDrconsumerenabled(drConnection.isEnabled());
if (drConnection.getPreferredSource() != null) {
cluster.setPreferredsource(drConnection.getPreferredSource());
} else {
// reset to -1, if this is an update catalog
cluster.setPreferredsource(-1);
}
hostLog.info("Configured connection for DR replica role to host " + drSource);
} else {
if (dr.getRole() == DrRoleType.XDCR) {
// consumer should be enabled even without connection source for XDCR
cluster.setDrconsumerenabled(true);
// reset to -1, if this is an update catalog
cluster.setPreferredsource(-1);
}
}
} else {
cluster.setDrrole(DrRoleType.NONE.value());
if (clusterType.getId() != null) {
clusterId = clusterType.getId();
} else {
clusterId = 0;
}
}
cluster.setDrclusterid(clusterId);
}
use of org.voltdb.catalog.Database in project voltdb by VoltDB.
the class CatalogUtil method setSnapshotInfo.
/**
* Set the auto-snapshot settings in the catalog from the deployment file
* @param catalog The catalog to be updated.
* @param snapshot A reference to the <snapshot> element of the deployment.xml file.
*/
private static void setSnapshotInfo(Catalog catalog, SnapshotType snapshotSettings) {
Database db = catalog.getClusters().get("cluster").getDatabases().get("database");
SnapshotSchedule schedule = db.getSnapshotschedule().add("default");
schedule.setEnabled(snapshotSettings.isEnabled());
String frequency = snapshotSettings.getFrequency();
if (!frequency.endsWith("s") && !frequency.endsWith("m") && !frequency.endsWith("h")) {
hostLog.error("Snapshot frequency " + frequency + " needs to end with time unit specified" + " that is one of [s, m, h] (seconds, minutes, hours)" + " Defaulting snapshot frequency to 10m.");
frequency = "10m";
}
int frequencyInt = 0;
String frequencySubstring = frequency.substring(0, frequency.length() - 1);
try {
frequencyInt = Integer.parseInt(frequencySubstring);
} catch (Exception e) {
hostLog.error("Frequency " + frequencySubstring + " is not an integer. Defaulting frequency to 10m.");
frequency = "10m";
frequencyInt = 10;
}
String prefix = snapshotSettings.getPrefix();
if (prefix == null || prefix.isEmpty()) {
hostLog.error("Snapshot prefix " + prefix + " is not a valid prefix. Using prefix of 'SNAPSHOTNONCE' ");
prefix = "SNAPSHOTNONCE";
}
if (prefix.contains("-") || prefix.contains(",")) {
String oldprefix = prefix;
prefix = prefix.replaceAll("-", "_");
prefix = prefix.replaceAll(",", "_");
hostLog.error("Snapshot prefix " + oldprefix + " cannot include , or -." + " Using the prefix: " + prefix + " instead.");
}
int retain = snapshotSettings.getRetain();
if (retain < 1) {
hostLog.error("Snapshot retain value " + retain + " is not a valid value. Must be 1 or greater." + " Defaulting snapshot retain to 1.");
retain = 1;
}
schedule.setFrequencyunit(frequency.substring(frequency.length() - 1, frequency.length()));
schedule.setFrequencyvalue(frequencyInt);
schedule.setPrefix(prefix);
schedule.setRetain(retain);
}
use of org.voltdb.catalog.Database in project voltdb by VoltDB.
the class CatalogUtil method setExportInfo.
/**
* Set deployment time settings for export
* @param catalog The catalog to be updated.
* @param exportsType A reference to the <exports> element of the deployment.xml file.
*/
private static void setExportInfo(Catalog catalog, ExportType exportType) {
final Cluster cluster = catalog.getClusters().get("cluster");
Database db = cluster.getDatabases().get("database");
if (DrRoleType.XDCR.value().equals(cluster.getDrrole())) {
// add default export configuration to DR conflict table
exportType = addExportConfigToDRConflictsTable(catalog, exportType);
}
if (exportType == null) {
return;
}
List<String> targetList = new ArrayList<>();
for (ExportConfigurationType exportConfiguration : exportType.getConfiguration()) {
boolean connectorEnabled = exportConfiguration.isEnabled();
String targetName = exportConfiguration.getTarget();
if (connectorEnabled) {
m_exportEnabled = true;
if (targetList.contains(targetName)) {
throw new RuntimeException("Multiple connectors can not be assigned to single export target: " + targetName + ".");
} else {
targetList.add(targetName);
}
}
Properties processorProperties = checkExportProcessorConfiguration(exportConfiguration);
org.voltdb.catalog.Connector catconn = db.getConnectors().get(targetName);
if (catconn == null) {
if (connectorEnabled) {
hostLog.info("Export configuration enabled and provided for export target " + targetName + " in deployment file however no export " + "tables are assigned to the this target. " + "Export target " + targetName + " will be disabled.");
}
continue;
}
// checking rowLengthLimit
int rowLengthLimit = Integer.parseInt(processorProperties.getProperty(ROW_LENGTH_LIMIT, "0"));
if (rowLengthLimit > 0) {
for (ConnectorTableInfo catTableinfo : catconn.getTableinfo()) {
Table tableref = catTableinfo.getTable();
int rowLength = Boolean.parseBoolean(processorProperties.getProperty("skipinternals", "false")) ? 0 : EXPORT_INTERNAL_FIELD_Length;
for (Column catColumn : tableref.getColumns()) {
rowLength += catColumn.getSize();
}
if (rowLength > rowLengthLimit) {
hostLog.error("Export configuration for export target " + targetName + " has" + "configured to has row length limit " + rowLengthLimit + ". But the export table " + tableref.getTypeName() + " has estimated row length " + rowLength + ".");
throw new RuntimeException("Export table " + tableref.getTypeName() + " row length is " + rowLength + ", exceeding configurated limitation " + rowLengthLimit + ".");
}
}
}
for (String name : processorProperties.stringPropertyNames()) {
ConnectorProperty prop = catconn.getConfig().add(name);
prop.setName(name);
prop.setValue(processorProperties.getProperty(name));
}
// on-server export always uses the guest processor
catconn.setLoaderclass(ExportManager.PROCESSOR_CLASS);
catconn.setEnabled(connectorEnabled);
if (!connectorEnabled) {
hostLog.info("Export configuration for export target " + targetName + " is present and is " + "configured to be disabled. Export target " + targetName + " will be disabled.");
} else {
hostLog.info("Export target " + targetName + " is configured and enabled with type=" + exportConfiguration.getType());
if (exportConfiguration.getProperty() != null) {
hostLog.info("Export target " + targetName + " configuration properties are: ");
for (PropertyType configProp : exportConfiguration.getProperty()) {
if (!configProp.getName().toLowerCase().contains("password")) {
hostLog.info("Export Configuration Property NAME=" + configProp.getName() + " VALUE=" + configProp.getValue());
}
}
}
}
}
}
Aggregations