Rearrange bucardo_config into the more standard "name" and "setting"
authorGreg Sabino Mullane <greg@endpoint.com>
Thu, 23 Feb 2012 19:00:22 +0000 (14:00 -0500)
committerGreg Sabino Mullane <greg@endpoint.com>
Thu, 23 Feb 2012 19:00:22 +0000 (14:00 -0500)
Add sync.synctype back in, so we can tell 'delta' from 'fullcopy'

Bucardo.pm
bucardo
bucardo.schema

index f74238f9f3b2e0497ad9640996c28102c6722348..6fdee023bb1650cbb94723f480cd48ca6babcfdb 100644 (file)
@@ -646,11 +646,13 @@ sub start_mcp {
     ## 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
@@ -4602,26 +4604,26 @@ sub reload_config_database {
         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();
diff --git a/bucardo b/bucardo
index 1d7a5800d2fe7dfec2a68898c6a31174640511eb..4e27bdfb8ec9dc2ff0471d681d8ebe9241559985 100755 (executable)
--- a/bucardo
+++ b/bucardo
@@ -455,7 +455,7 @@ sub get_config {
 
     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) {
@@ -3811,6 +3811,7 @@ sub add_sync {
     ## 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
@@ -3836,7 +3837,8 @@ sub add_sync {
     };
 
     ## 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 = [
         {
@@ -6433,7 +6435,7 @@ sub config_exists {
 
     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();
@@ -6919,7 +6921,7 @@ sub upgrade {
 
     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'],
     );
 
@@ -7220,15 +7222,15 @@ sub upgrade {
     ## 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;
@@ -7245,14 +7247,14 @@ sub upgrade {
             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};
@@ -7399,7 +7401,7 @@ sub upgrade {
     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";
@@ -7561,9 +7563,9 @@ Use "add table all" to add in all tables};
     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>
@@ -7861,7 +7863,7 @@ sub config {
         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) {
@@ -8233,7 +8235,7 @@ sub install {
     $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) {
@@ -9294,7 +9296,7 @@ information is loaded.
 
 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>
index 893ed804f83e1c4f2b86cb0e9c152745ddd2c42f..70e67e47c9d9b95ab40a6f5fd8fac9b09b946e0b 100644 (file)
@@ -48,18 +48,18 @@ $bc$;
 -- 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'));
 
@@ -71,16 +71,16 @@ BEGIN
 
   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;
@@ -95,7 +95,7 @@ CREATE TRIGGER check_bucardo_config
   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?
@@ -113,7 +113,7 @@ vac_run|30|How often does the VAC process run?
 
 
 -- 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?
@@ -127,7 +127,7 @@ tcp_keepalives_count|0|How many probes to send. 0 indicates sticking with system
 
 
 -- 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?
@@ -141,7 +141,7 @@ warning_file|bucardo.warning.log|File containing all log lines starting with "Wa
 \.
 
 -- 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
@@ -149,7 +149,7 @@ bucardo_current_version|4.99.4|Current version of Bucardo
 \.
 
 -- 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?
@@ -170,7 +170,7 @@ syslog_facility|LOG_LOCAL1|Which syslog facility level to use
 \.
 
 -- 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?
@@ -389,6 +389,7 @@ CREATE TRIGGER herdcheck
 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,
@@ -2353,7 +2354,7 @@ SELECT 'Fixme'::TEXT;
 
 ## 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};
@@ -2568,9 +2569,9 @@ CREATE TABLE bucardo.upgrade_log (
 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