merge with tridges tree to resolve all conflicts
authorRonnie Sahlberg <sahlberg@ronnie>
Wed, 2 May 2007 00:53:29 +0000 (10:53 +1000)
committerRonnie Sahlberg <sahlberg@ronnie>
Wed, 2 May 2007 00:53:29 +0000 (10:53 +1000)
1  2 
Makefile.in
common/cmdline.c
common/ctdb.c
common/ctdb_client.c
common/ctdb_control.c
include/ctdb.h
include/ctdb_private.h
tests/ctdb_fetch.c
tests/ctdb_test.c
tools/ctdb_control.c

diff --cc Makefile.in
index ff53535c904b4d3878bdb644688e110bff24fee2,75fb3cb1cf2345faf5f7f895cbd0db51a285be8e..7d4e4370ec6dba425fe86dc3b56f712b6202fb64
@@@ -111,18 -115,12 +115,18 @@@ install: al
        rsync $(BINS) $(bindir)
        rsync $(srcdir)/include/ctdb.h $(includedir)
  
- test:
+ test: all
        tests/run_tests.sh
  
- valgrindtest:
+ valgrindtest: all
        VALGRIND="valgrind -q --trace-children=yes" tests/run_tests.sh
  
 +test:
 +      tests/run_tests.sh
 +
 +valgrindtest:
 +      VALGRIND="valgrind -q --trace-children=yes" tests/run_tests.sh
 +
  
  realdistclean: distclean
        rm -f configure config.h.in
Simple merge
diff --cc common/ctdb.c
Simple merge
index 5b6031852d38360ad4d6979e7710e8942ddb5bf1,87960d344e3f5b6d8bc22f19c185c59ab05895c5..40857110be71955a5a3dd9171eb3c210c50dda6d
@@@ -793,53 -798,6 +798,53 @@@ int ctdb_ctrl_getvnnmap(struct ctdb_con
        return 0;
  }
  
-                          CTDB_CONTROL_GET_RECMODE, data, 
 +/*
 +  get the recovery mode of a remote node
 + */
 +int ctdb_ctrl_getrecmode(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *recmode)
 +{
 +      int ret;
 +      TDB_DATA data, outdata;
 +      int32_t res;
 +
 +      ZERO_STRUCT(data);
 +      ret = ctdb_control(ctdb, destnode, 0, 
-                          CTDB_CONTROL_SET_RECMODE, data, 
++                         CTDB_CONTROL_GET_RECMODE, 0, data, 
 +                         ctdb, &outdata, &res);
 +      if (ret != 0 || res != 0) {
 +              DEBUG(0,(__location__ " ctdb_control for getrecmode failed\n"));
 +              return -1;
 +      }
 +
 +      *recmode = ((uint32_t *)outdata.dptr)[0];
 +
 +      return 0;
 +}
 +
 +/*
 +  set the recovery mode of a remote node
 + */
 +int ctdb_ctrl_setrecmode(struct ctdb_context *ctdb, uint32_t destnode, uint32_t recmode)
 +{
 +      int ret;
 +      TDB_DATA data, outdata;
 +      int32_t res;
 +
 +      ZERO_STRUCT(data);
 +      data.dsize = sizeof(uint32_t);
 +      data.dptr = (unsigned char *)&recmode;
 +
 +      ret = ctdb_control(ctdb, destnode, 0, 
++                         CTDB_CONTROL_SET_RECMODE, 0, data, 
 +                         ctdb, &outdata, &res);
 +      if (ret != 0 || res != 0) {
 +              DEBUG(0,(__location__ " ctdb_control for getrecmode failed\n"));
 +              return -1;
 +      }
 +
 +      return 0;
 +}
 +
  /*
    get a list of databases off a remote node
   */
@@@ -935,157 -897,6 +940,157 @@@ int ctdb_ctrl_setvnnmap(struct ctdb_con
        return 0;
  }
  
-                          CTDB_CONTROL_PULL_DB, indata, 
 +/*
 +  get all keys and records for a specific database
 + */
 +int ctdb_ctrl_pulldb(struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid, uint32_t lmaster, TALLOC_CTX *mem_ctx, struct ctdb_key_list *keys)
 +{
 +      int i, ret;
 +      TDB_DATA indata, outdata;
 +      int32_t res;
 +      unsigned char *ptr;
 +
 +      indata.dsize = 2*sizeof(uint32_t);
 +      indata.dptr  = (unsigned char *)talloc_array(mem_ctx, uint32_t, 2);
 +
 +      ((uint32_t *)(&indata.dptr[0]))[0] = dbid;
 +      ((uint32_t *)(&indata.dptr[0]))[1] = lmaster;
 +
 +      ret = ctdb_control(ctdb, destnode, 0, 
-                          CTDB_CONTROL_PULL_DB, indata, 
++                         CTDB_CONTROL_PULL_DB, 0, indata, 
 +                         mem_ctx, &outdata, &res);
 +      if (ret != 0 || res != 0) {
 +              DEBUG(0,(__location__ " ctdb_control for pulldb failed\n"));
 +              return -1;
 +      }
 +
 +
 +      keys->dbid   = ((uint32_t *)(&outdata.dptr[0]))[0];
 +      keys->num    = ((uint32_t *)(&outdata.dptr[0]))[1];
 +      keys->keys   =talloc_array(mem_ctx, TDB_DATA, keys->num);
 +      keys->headers=talloc_array(mem_ctx, struct ctdb_ltdb_header, keys->num);
 +      keys->lmasters=talloc_array(mem_ctx, uint32_t, keys->num);
 +      keys->data=talloc_array(mem_ctx, TDB_DATA, keys->num);
 +
 +      /* loop over all key/data pairs */
 +      ptr=&outdata.dptr[8];
 +      for(i=0;i<keys->num;i++){
 +              uint32_t len;
 +              TDB_DATA *key, *data;
 +
 +              keys->lmasters[i]= *((uint32_t *)ptr);
 +              ptr+=4;
 +
 +              key=&keys->keys[i];
 +              key->dsize= *((uint32_t *)ptr);
 +              ptr+=4;
 +              key->dptr=talloc_size(mem_ctx, key->dsize);
 +              memcpy(key->dptr, ptr, key->dsize);
 +              len = (key->dsize+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
 +              ptr+=len;
 +
 +              memcpy(&keys->headers[i], ptr, sizeof(struct ctdb_ltdb_header));
 +              len = (sizeof(struct ctdb_ltdb_header)+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
 +              ptr+=len;
 +
 +              data=&keys->data[i];
 +              data->dsize= *((uint32_t *)ptr);
 +              ptr+=4;
 +              data->dptr=talloc_size(mem_ctx, data->dsize);
 +              memcpy(data->dptr, ptr, data->dsize);
 +              len = (data->dsize+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
 +              ptr+=len;
 +
 +      }
 +
 +      return 0;
 +}
 +
 +/*
 +  copy a tdb from one node to another node
 + */
 +int ctdb_ctrl_copydb(struct ctdb_context *ctdb, uint32_t sourcenode, uint32_t destnode, uint32_t dbid, uint32_t lmaster, TALLOC_CTX *mem_ctx)
 +{
 +      int ret;
 +      TDB_DATA indata, outdata;
 +      int32_t res;
 +
 +      indata.dsize = 2*sizeof(uint32_t);
 +      indata.dptr  = (unsigned char *)talloc_array(mem_ctx, uint32_t, 2);
 +
 +      ((uint32_t *)(&indata.dptr[0]))[0] = dbid;
 +      ((uint32_t *)(&indata.dptr[0]))[1] = lmaster;
 +
 +      ret = ctdb_control(ctdb, sourcenode, 0, 
-                          CTDB_CONTROL_SET_DMASTER, indata, 
++                         CTDB_CONTROL_PULL_DB, 0, indata, 
 +                         mem_ctx, &outdata, &res);
 +      if (ret != 0 || res != 0) {
 +              DEBUG(0,(__location__ " ctdb_control for pulldb failed\n"));
 +              return -1;
 +      }
 +
 +      ret = ctdb_control(ctdb, destnode, 0, 
 +                         CTDB_CONTROL_PUSH_DB, outdata, 
 +                         mem_ctx, NULL, &res);
 +      if (ret != 0 || res != 0) {
 +              DEBUG(0,(__location__ " ctdb_control for pushdb failed\n"));
 +              return -1;
 +      }
 +
 +      return 0;
 +}
 +
 +/*
 +  change dmaster for all keys in the database to the new value
 + */
 +int ctdb_ctrl_setdmaster(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t dmaster)
 +{
 +      int ret;
 +      TDB_DATA indata, outdata;
 +      int32_t res;
 +
 +      indata.dsize = 2*sizeof(uint32_t);
 +      indata.dptr = (unsigned char *)talloc_array(mem_ctx, uint32_t, 2);
 +
 +      ((uint32_t *)(&indata.dptr[0]))[0] = dbid;
 +      ((uint32_t *)(&indata.dptr[0]))[1] = dmaster;
 +
 +      ret = ctdb_control(ctdb, destnode, 0, 
-                          CTDB_CONTROL_CLEAR_DB, indata, 
++                         CTDB_CONTROL_SET_DMASTER, 0, indata, 
 +                         mem_ctx, &outdata, &res);
 +      if (ret != 0 || res != 0) {
 +              DEBUG(0,(__location__ " ctdb_control for setdmaster failed\n"));
 +              return -1;
 +      }
 +
 +      return 0;
 +}
 +
 +/*
 +  delete all records from a tdb
 + */
 +int ctdb_ctrl_cleardb(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid)
 +{
 +      int ret;
 +      TDB_DATA indata, outdata;
 +      int32_t res;
 +
 +      indata.dsize = sizeof(uint32_t);
 +      indata.dptr = (unsigned char *)talloc_array(mem_ctx, uint32_t, 1);
 +
 +      ((uint32_t *)(&indata.dptr[0]))[0] = dbid;
 +
 +      ret = ctdb_control(ctdb, destnode, 0, 
++                         CTDB_CONTROL_CLEAR_DB, 0, indata, 
 +                         mem_ctx, &outdata, &res);
 +      if (ret != 0 || res != 0) {
 +              DEBUG(0,(__location__ " ctdb_control for cleardb failed\n"));
 +              return -1;
 +      }
 +
 +      return 0;
 +}
 +
  /*
    ping a node, return number of clients connected
   */
index eb4775d30daf3efe1df51e9daf54e29d52858a68,7bc705d60a1664f9f8f63017679833a67b127b47..cda496b3e4250e3fdeec1f0b67d3c07be891f677
@@@ -42,96 -41,7 +42,95 @@@ struct ctdb_control_state 
   } \
   } while (0)
  
 +static int traverse_cleardb(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *p)
 +{
 +      int ret;
 +
 +
 +      ret = tdb_delete(tdb, key);
 +      if (ret) {
 +              DEBUG(0,(__location__ "failed to delete tdb record\n"));
 +              return ret;
 +      }
 +      return 0;
 +}
 +
 +static int traverse_setdmaster(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *p)
 +{
 +      uint32_t *dmaster = (uint32_t *)p;
 +      struct ctdb_ltdb_header *header = (struct ctdb_ltdb_header *)data.dptr;
 +      int ret;
 +
 +      header->dmaster = *dmaster;
 +
 +      ret = tdb_store(tdb, key, data, TDB_REPLACE);
 +      if (ret) {
 +              DEBUG(0,(__location__ "failed to write tdb data back  ret:%d\n",ret));
 +              return ret;
 +      }
 +      return 0;
 +}
 +
 +struct getkeys_params {
 +      struct ctdb_db_context *ctdb_db;
 +      TDB_DATA *outdata;
 +      uint32_t lmaster;
 +};
 +
 +static int traverse_getkeys(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *p)
 +{
 +      struct getkeys_params *params = (struct getkeys_params *)p;
 +      TDB_DATA *outdata = talloc_get_type(params->outdata, TDB_DATA);
 +      struct ctdb_db_context *ctdb_db = talloc_get_type(params->ctdb_db, struct ctdb_db_context);
 +      unsigned char *ptr;
 +      int len;
 +      uint32_t lmaster;
 +
 +      lmaster = ctdb_lmaster(ctdb_db->ctdb, &key);
 +
 +      /* only include this record if the lmaster matches or if
 +         the wildcard lmaster (-1) was specified.
 +      */
 +      if((lmaster!=CTDB_LMASTER_ANY)
 +      && (lmaster!=params->lmaster) ){
 +              return 0;
 +      }
 +
 +      len=outdata->dsize;
 +      len+=4; /*lmaster*/
 +      len+=4; /*key len*/
 +      len+=key.dsize;
 +      len=(len+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
 +      len+=sizeof(struct ctdb_ltdb_header);
 +      len=(len+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
 +      len+=4; /*data len */
 +      len+=data.dsize;
 +      len=(len+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
  
 +      ptr=outdata->dptr=talloc_realloc_size(outdata, outdata->dptr, len);
 +      ptr+=outdata->dsize;
 +      outdata->dsize=len;
 +      /* number of records is stored as the second 4 bytes */
 +      ((uint32_t *)(&outdata->dptr[0]))[1]++;
 +
 +      *((uint32_t *)ptr)=lmaster;
 +      ptr+=4;
 +
 +      *((uint32_t *)ptr)=key.dsize;
 +      ptr+=4;
 +      memcpy(ptr, key.dptr, key.dsize);
 +      ptr+= (key.dsize+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
 +
 +      memcpy(ptr, data.dptr, sizeof(struct ctdb_ltdb_header));
 +      ptr+=(sizeof(struct ctdb_ltdb_header)+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
 +
 +      *((uint32_t *)ptr)=data.dsize-sizeof(struct ctdb_ltdb_header);
 +      ptr+=4;
 +      memcpy(ptr, data.dptr+sizeof(struct ctdb_ltdb_header), data.dsize-sizeof(struct ctdb_ltdb_header));
 +      ptr+= (data.dsize-sizeof(struct ctdb_ltdb_header)+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
 +
 +      return 0;
 +}
  
  /*
    process a control request
diff --cc include/ctdb.h
Simple merge
index e9a9e3e689de11e5aa38e43e3509268099a28596,8b75ec4c04a3049d649a3b1fa24d7d1ee22a7ccb..e2528bff4318ebd3407d96421444aaa06ef031c3
@@@ -253,13 -256,19 +257,26 @@@ enum ctdb_controls {CTDB_CONTROL_PROCES
                    CTDB_CONTROL_SET_DEBUG,
                    CTDB_CONTROL_GET_DBMAP,
                    CTDB_CONTROL_GET_NODEMAP,
-                   CTDB_CONTROL_STATUS_RESET};
 +                  CTDB_CONTROL_SET_DMASTER,
 +                  CTDB_CONTROL_CLEAR_DB,
 +                  CTDB_CONTROL_PULL_DB,
 +                  CTDB_CONTROL_PUSH_DB,
 +                  CTDB_CONTROL_GET_RECMODE,
 +                  CTDB_CONTROL_SET_RECMODE,
+                   CTDB_CONTROL_STATUS_RESET,
+                   CTDB_CONTROL_DB_ATTACH,
+                   CTDB_CONTROL_SET_CALL};
+ /*
+   structure passed in set_call control
+  */
+ struct ctdb_control_set_call {
+       uint32_t db_id;
+       ctdb_fn_t fn;
+       uint32_t id;
+ };
++>>>>>>> MERGE-SOURCE
  
  enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
  
Simple merge
Simple merge
index 117a6ad23d50412fe964aae2eb69a76bc52e724e,37a068a15bec4a88d7886de94ac428741e6a3371..a2cde90bc8bfbc565a93ffa4f5e4f76645415715
@@@ -883,8 -533,8 +908,10 @@@ int main(int argc, const char *argv[]
                ret = control_debug(ctdb, extra_argc-1, extra_argv+1);
        } else if (strcmp(control, "debuglevel") == 0) {
                ret = control_debuglevel(ctdb, extra_argc-1, extra_argv+1);
 +      } else if (strcmp(control, "recover") == 0) {
 +              ret = control_recover(ctdb, extra_argc-1, extra_argv+1);
+       } else if (strcmp(control, "attach") == 0) {
+               ret = control_attach(ctdb, extra_argc-1, extra_argv+1);
        } else {
                printf("Unknown control '%s'\n", control);
                exit(1);