## Let any listeners know we have gotten this far
$self->db_notify($masterdbh, 'started', 1);
- ## Kick all syncs that may have sent a notice while we were down.
+ ## Because a sync may have gotten a notice while we were down,
+ ## we auto-kick all eligible syncs
for my $syncname (keys %{ $self->{sync} }) {
+
my $s = $self->{sync}{$syncname};
- ## Start ina non-kicked mode
+ ## Default to starting in a non-kicked mode
$s->{kick_on_startup} = 0;
## Skip inactive syncs
DEBUG => 4,
);
- $SQL = 'SELECT setting,value,about,type,name FROM bucardo_config';
+ $SQL = 'SELECT name,setting,about,type,name FROM bucardo_config';
$sth = $self->{masterdbh}->prepare($SQL);
$sth->execute();
for my $row (@{$sth->fetchall_arrayref({})}) {
## Things from an rc file can override the value in the db
- my $value = exists $self->{$row->{setting}} ? $self->{$row->{setting}} : $row->{value};
- if ($row->{setting} eq 'log_level') {
- my $newvalue = $log_level_number{uc $value};
+ my $setting = exists $self->{$row->{name}} ? $self->{$row->{name}} : $row->{setting};
+ if ($row->{name} eq 'log_level') {
+ my $newvalue = $log_level_number{uc $setting};
if (! defined $newvalue) {
die "Invalid log_level!\n";
}
$config{log_level_number} = $newvalue;
}
if (defined $row->{type}) {
- $config{$row->{type}}{$row->{name}}{$row->{setting}} = $value;
+ $config{$row->{type}}{$row->{name}}{$row->{setting}} = $setting;
$config_about{$row->{type}}{$row->{name}}{$row->{setting}} = $row->{about};
}
else {
- $config{$row->{setting}} = $value;
- $config_about{$row->{setting}} = $row->{about};
+ $config{$row->{name}} = $setting;
+ $config_about{$row->{name}} = $row->{about};
}
}
$self->{masterdbh}->commit();
my $name = shift;
- $SQL = 'SELECT value FROM bucardo.bucardo_config WHERE LOWER(setting) = ?';
+ $SQL = 'SELECT setting FROM bucardo.bucardo_config WHERE LOWER(name) = ?';
$sth = $dbh->prepare_cached($SQL);
$count = $sth->execute(lc $name);
if ($count < 1) {
## Inputs and aliases, database column name, flags, default
my $validcols = qq{
name name 0 $item_name
+ synctype|type synctype 0 null
herd herd 0 null
dbs dbs 0 null
stayalive stayalive TF null
};
## Fullcopy syncs get some of their defaults overriden
- ## Because who wants ping on a fullcopy sync?
+ ## The controllers and kids never start automatically,
+ ## and ping is never on
my $morph = [
{
my $name = shift;
- my $SQL = 'SELECT 1 FROM bucardo.bucardo_config WHERE setting = ?';
+ my $SQL = 'SELECT 1 FROM bucardo.bucardo_config WHERE name = ?';
my $sth = $dbh->prepare_cached($SQL);
my $count = $sth->execute($name);
$sth->finish();
my @row_values = (
- ['bucardo_config','about',q{setting = 'log_showtime'}, 1,
+ ['bucardo_config','about',q{name = 'log_showtime'}, 1,
'Show timestamp in the log output? 0=off 1=seconds since epoch 2=scalar gmtime 3=scalar localtime'],
);
## Drop any old config items
for my $name (@old_configs) {
next if ! config_exists($name);
- clog "Removed old bucardo_config setting: $name";
- upgrade_and_log(qq{DELETE FROM bucardo.bucardo_config WHERE setting = '$name'});
+ clog "Removed old bucardo_config name: $name";
+ upgrade_and_log(qq{DELETE FROM bucardo.bucardo_config WHERE name = '$name'});
$changes++;
}
## Check for any new config items
- $SQL = 'SELECT value FROM bucardo.bucardo_config WHERE lower(setting) = ?';
+ $SQL = 'SELECT setting FROM bucardo.bucardo_config WHERE lower(name) = ?';
my $cfgsth = $dbh->prepare($SQL);
- $SQL = 'INSERT INTO bucardo.bucardo_config(setting,value,about) VALUES (?,?,?)';
+ $SQL = 'INSERT INTO bucardo.bucardo_config(name,setting,about) VALUES (?,?,?)';
my $newcfg = $dbh->prepare($SQL);
my %config;
my $inside = 0;
next;
}
## Scoop
- my ($setting,$value,$about) = split /\|/ => $_;
- $config{$setting} = [$value,$about];
- $count = $cfgsth->execute($setting);
+ my ($name,$setting,$about) = split /\|/ => $_;
+ $config{$name} = [$setting,$about];
+ $count = $cfgsth->execute($name);
$cfgsth->finish();
if ($count eq '0E0') {
- clog "Added new bucardo_config setting: $setting";
+ clog "Added new bucardo_config name: $name";
$changes++;
- $newcfg->execute($setting,$value,$about);
+ $newcfg->execute($name,$setting,$about);
}
}
close $fh or die qq{Could not close file "$file": $!\n};
else {
my $curval = $cfgsth->fetchall_arrayref()->[0][0];
if ($curval ne $schema_version) {
- $SQL = 'UPDATE bucardo.bucardo_config SET value = ? WHERE setting = ?';
+ $SQL = 'UPDATE bucardo.bucardo_config SET setting = ? WHERE name = ?';
my $updatecfg = $dbh->prepare($SQL);
$updatecfg->execute($schema_version, 'bucardo_current_version');
clog "Set bucardo_config.bucardo_current_version to $schema_version";
if ('config' eq $name) {
return q{Usage: config show [all | name]
Usage: config set foo=bar [foo2=bar2]
-Displays or sets settings from the bucardo_config table.
-Using 'show' will display all settings or a subset based on the given name.
-Using 'set' will change one or more settings.};
+Displays or sets items from the bucardo_config table.
+Using 'show' will display all items or a subset based on the given name.
+Using 'set' will change one or more items.};
}
if ('inspect' eq $name) {
return q{Usage: inspect <type> <name>
exit 1;
}
- $SQL = 'UPDATE bucardo.bucardo_config SET value = ? WHERE setting = ?';
+ $SQL = 'UPDATE bucardo.bucardo_config SET setting = ? WHERE name = ?';
$sth = $dbh->prepare($SQL);
for my $noun (@nouns) {
$dbh = DBI->connect($BDSN, 'bucardo', '', {AutoCommit=>0,RaiseError=>1,PrintError=>0});
$dbh->do('SET search_path = bucardo');
- $SQL = 'UPDATE bucardo.bucardo_config SET value = ? WHERE setting = ?';
+ $SQL = 'UPDATE bucardo.bucardo_config SET setting = ? WHERE name = ?';
$sth = $dbh->prepare($SQL);
$confvar{piddir} = $piddir;
for my $key (sort keys %confvar) {
Usage: ./bucardo show <all|setting1> [setting2..]
-Shows the current values in the bucardo_config table. Use the keyword 'all' to see all the settings, or
+Shows the current settings in the bucardo_config table. Use the keyword 'all' to see all the settings, or
specify one or more search terms.
=item B<set>
-- Main bucardo configuration information
--
CREATE TABLE bucardo.bucardo_config (
- setting TEXT NOT NULL, -- short unique name, maps to %config inside Bucardo
- value TEXT NOT NULL,
+ name TEXT NOT NULL, -- short unique name, maps to %config inside Bucardo
+ setting TEXT NOT NULL,
about TEXT NULL, -- long description
type TEXT NULL, -- sync or goat
- name TEXT NULL, -- which specific sync or goat
+ item TEXT NULL, -- which specific sync or goat
cdate TIMESTAMPTZ NOT NULL DEFAULT now()
);
COMMENT ON TABLE bucardo.bucardo_config IS $$Contains configuration variables for a specific Bucardo instance$$;
-CREATE UNIQUE INDEX bucardo_config_unique ON bucardo.bucardo_config(LOWER(setting)) WHERE name IS NULL;
+CREATE UNIQUE INDEX bucardo_config_unique ON bucardo.bucardo_config(LOWER(name)) WHERE item IS NULL;
-CREATE UNIQUE INDEX bucardo_config_unique_name ON bucardo.bucardo_config(setting,name,type) WHERE name IS NOT NULL;
+CREATE UNIQUE INDEX bucardo_config_unique_name ON bucardo.bucardo_config(name,item,type) WHERE item IS NOT NULL;
ALTER TABLE bucardo.bucardo_config ADD CONSTRAINT valid_config_type CHECK (type IN ('sync','goat'));
NEW.setting = LOWER(NEW.setting);
- IF (NEW.type IS NOT NULL and NEW.name IS NULL) THEN
+ IF (NEW.type IS NOT NULL and NEW.item IS NULL) THEN
RAISE EXCEPTION 'Must provide a specific %', NEW.type;
END IF;
- IF (NEW.name IS NOT NULL and NEW.type IS NULL) THEN
+ IF (NEW.item IS NOT NULL and NEW.type IS NULL) THEN
RAISE EXCEPTION 'Must provide a type if giving a name';
END IF;
- IF (NEW.setting = 'sync' OR NEW.setting = 'goat') THEN
- RAISE EXCEPTION 'Invalid setting name';
+ IF (NEW.name = 'sync' OR NEW.name = 'goat') THEN
+ RAISE EXCEPTION 'Invalid configuration name';
END IF;
RETURN NEW;
FOR EACH ROW EXECUTE PROCEDURE bucardo.check_bucardo_config();
-- Sleep times (all in seconds)
-COPY bucardo.bucardo_config(setting,value,about)
+COPY bucardo.bucardo_config("name",setting,about)
FROM STDIN
WITH DELIMITER '|';
mcp_loop_sleep|0.5|How long does the main MCP daemon sleep between loops?
-- Various timeouts (times are in seconds)
-COPY bucardo.bucardo_config(setting,value,about)
+COPY bucardo.bucardo_config("name",setting,about)
FROM STDIN
WITH DELIMITER '|';
mcp_pingtime|60|How often do we ping check the MCP?
-- Logging
-COPY bucardo.bucardo_config(setting,value,about)
+COPY bucardo.bucardo_config(name,setting,about)
FROM STDIN
WITH DELIMITER '|';
log_microsecond|0|Show microsecond output in the timestamps?
\.
-- Versioning
-COPY bucardo.bucardo_config(setting,value,about)
+COPY bucardo.bucardo_config(name,setting,about)
FROM STDIN
WITH DELIMITER '|';
bucardo_version|4.99.4|Bucardo version this schema was created with
\.
-- Other settings:
-COPY bucardo.bucardo_config(setting,value,about)
+COPY bucardo.bucardo_config(name,setting,about)
FROM STDIN
WITH DELIMITER '|';
bucardo_vac|1|Do we want the automatic VAC daemon to run?
\.
-- Unused at the moment:
-COPY bucardo.bucardo_config(setting,value,about)
+COPY bucardo.bucardo_config(name,setting,about)
FROM STDIN
WITH DELIMITER '|';
autosync_ddl|newcol|Which DDL changing conditions do we try to remedy automatically?
CREATE TABLE bucardo.sync (
name TEXT NOT NULL UNIQUE,
CONSTRAINT sync_name_pk PRIMARY KEY (name),
+ synctype TEXT NOT NULL DEFAULT 'delta',
herd TEXT NULL,
CONSTRAINT sync_herd_fk FOREIGN KEY (herd) REFERENCES bucardo.herd(name) ON UPDATE CASCADE ON DELETE RESTRICT,
dbs TEXT NULL,
## Gather information from bucardo_config
my $config;
-$SQL = 'SELECT setting,value FROM bucardo_config';
+$SQL = 'SELECT name,setting FROM bucardo_config';
$rv = spi_exec_query($SQL);
for my $row (@{$rv->{rows}}) {
$config->{$row->{setting}} = $row->{value};
COMMENT ON TABLE bucardo.upgrade_log IS $$Historical record of upgrade actions$$;
INSERT INTO bucardo.upgrade_log(action,summary,version)
- SELECT 'Initial install', '', value
+ SELECT 'Initial install', '', setting
FROM bucardo.bucardo_config
- WHERE setting = 'bucardo_version';
+ WHERE name = 'bucardo_version';
-- Allow users to insert messages in the Bucardo logs