[BACK]Return to dlz_postgres_driver.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / external / mpl / bind / dist / contrib / dlz / drivers

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/external/mpl/bind/dist/contrib/dlz/drivers/Attic/dlz_postgres_driver.c between version 1.2 and 1.3

version 1.2, 2018/08/12 13:02:31 version 1.3, 2019/01/09 16:55:05
Line 151  postgres_makesafe(char *to, const char *
Line 151  postgres_makesafe(char *to, const char *
         return target - to;          return target - to;
 }  }
   
 #ifdef ISC_PLATFORM_USETHREADS  
   
 /*%  /*%
  * Properly cleans up a list of database instances.   * Properly cleans up a list of database instances.
  * This function is only used when the driver is compiled for   * This function is only used when the driver is compiled for
Line 227  postgres_find_avail_conn(db_list_t *dbli
Line 225  postgres_find_avail_conn(db_list_t *dbli
         return NULL;          return NULL;
 }  }
   
 #endif /* ISC_PLATFORM_USETHREADS */  
   
 /*%  /*%
  * Allocates memory for a new string, and then constructs the new   * Allocates memory for a new string, and then constructs the new
  * string by "escaping" the input string.  The new string is   * string by "escaping" the input string.  The new string is
Line 300  postgres_get_resultset(const char *zone,
Line 296  postgres_get_resultset(const char *zone,
 #endif  #endif
   
         /* get db instance / connection */          /* get db instance / connection */
 #ifdef ISC_PLATFORM_USETHREADS  
   
         /* find an available DBI from the list */          /* find an available DBI from the list */
         dbi = postgres_find_avail_conn((db_list_t *) dbdata);          dbi = postgres_find_avail_conn((db_list_t *) dbdata);
   
 #else /* ISC_PLATFORM_USETHREADS */  
   
         /*  
          * only 1 DBI - no need to lock instance lock either  
          * only 1 thread in the whole process, no possible contention.  
          */  
         dbi =  (dbinstance_t *) dbdata;  
   
 #endif /* ISC_PLATFORM_USETHREADS */  
   
 #if 0  #if 0
         /* temporary logging message */          /* temporary logging message */
         isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,          isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
Line 601  postgres_get_resultset(const char *zone,
Line 586  postgres_get_resultset(const char *zone,
         if (dbi->client != NULL)          if (dbi->client != NULL)
                 isc_mem_free(named_g_mctx, dbi->client);                  isc_mem_free(named_g_mctx, dbi->client);
   
 #ifdef ISC_PLATFORM_USETHREADS  
   
 #if 0  #if 0
         /* temporary logging message */          /* temporary logging message */
         isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,          isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
Line 613  postgres_get_resultset(const char *zone,
Line 596  postgres_get_resultset(const char *zone,
         /* release the lock so another thread can use this dbi */          /* release the lock so another thread can use this dbi */
         isc_mutex_unlock(&dbi->instance_lock);          isc_mutex_unlock(&dbi->instance_lock);
   
 #endif /* ISC_PLATFORM_USETHREADS */  
   
         /* release query string */          /* release query string */
         if (querystring  != NULL)          if (querystring  != NULL)
                 isc_mem_free(named_g_mctx, querystring );                  isc_mem_free(named_g_mctx, querystring );
Line 1060  postgres_create(const char *dlzname, uns
Line 1041  postgres_create(const char *dlzname, uns
         dbinstance_t *dbi = NULL;          dbinstance_t *dbi = NULL;
         unsigned int j;          unsigned int j;
   
 #ifdef ISC_PLATFORM_USETHREADS  
         /* if multi-threaded, we need a few extra variables. */          /* if multi-threaded, we need a few extra variables. */
         int dbcount;          int dbcount;
         db_list_t *dblist = NULL;          db_list_t *dblist = NULL;
         int i;          int i;
         char *endp;          char *endp;
   
 #endif /* ISC_PLATFORM_USETHREADS */  
   
         UNUSED(driverarg);          UNUSED(driverarg);
         UNUSED(dlzname);          UNUSED(dlzname);
   
Line 1076  postgres_create(const char *dlzname, uns
Line 1054  postgres_create(const char *dlzname, uns
         srand( (unsigned)time( NULL ) );          srand( (unsigned)time( NULL ) );
   
   
 #ifdef ISC_PLATFORM_USETHREADS  
         /* if debugging, let user know we are multithreaded. */          /* if debugging, let user know we are multithreaded. */
         isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,          isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
                       DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),                        DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),
                       "Postgres driver running multithreaded");                        "Postgres driver running multithreaded");
 #else /* ISC_PLATFORM_USETHREADS */  
         /* if debugging, let user know we are single threaded. */  
         isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,  
                       DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),  
                       "Postgres driver running single threaded");  
 #endif /* ISC_PLATFORM_USETHREADS */  
   
         /* verify we have at least 5 arg's passed to the driver */          /* verify we have at least 5 arg's passed to the driver */
         if (argc < 5) {          if (argc < 5) {
Line 1107  postgres_create(const char *dlzname, uns
Line 1078  postgres_create(const char *dlzname, uns
         }          }
   
         /* multithreaded build can have multiple DB connections */          /* multithreaded build can have multiple DB connections */
 #ifdef ISC_PLATFORM_USETHREADS  
   
         /* check how many db connections we should create */          /* check how many db connections we should create */
         dbcount = strtol(argv[1], &endp, 10);          dbcount = strtol(argv[1], &endp, 10);
Line 1133  postgres_create(const char *dlzname, uns
Line 1103  postgres_create(const char *dlzname, uns
          */           */
         for (i=0; i < dbcount; i++) {          for (i=0; i < dbcount; i++) {
   
 #endif /* ISC_PLATFORM_USETHREADS */  
   
                 /* how many queries were passed in from config file? */                  /* how many queries were passed in from config file? */
                 switch(argc) {                  switch(argc) {
                 case 5:                  case 5:
Line 1176  postgres_create(const char *dlzname, uns
Line 1144  postgres_create(const char *dlzname, uns
                         goto cleanup;                          goto cleanup;
                 }                  }
   
 #ifdef ISC_PLATFORM_USETHREADS  
   
                 /* when multithreaded, build a list of DBI's */                  /* when multithreaded, build a list of DBI's */
                 ISC_LINK_INIT(dbi, link);                  ISC_LINK_INIT(dbi, link);
                 ISC_LIST_APPEND(*dblist, dbi, link);                  ISC_LIST_APPEND(*dblist, dbi, link);
   
 #endif  
   
                 /* create and set db connection */                  /* create and set db connection */
                 dbi->dbconn = PQconnectdb(argv[2]);                  dbi->dbconn = PQconnectdb(argv[2]);
                 /*                  /*
Line 1206  postgres_create(const char *dlzname, uns
Line 1170  postgres_create(const char *dlzname, uns
                         PQreset((PGconn *) dbi->dbconn);                          PQreset((PGconn *) dbi->dbconn);
   
   
 #ifdef ISC_PLATFORM_USETHREADS  
   
                 /*                  /*
                  * if multi threaded, let user know which connection                   * if multi threaded, let user know which connection
                  * failed.  user could be attempting to create 10 db                   * failed.  user could be attempting to create 10 db
Line 1231  postgres_create(const char *dlzname, uns
Line 1193  postgres_create(const char *dlzname, uns
                 /* set dbdata to the list we created. */                  /* set dbdata to the list we created. */
         *dbdata = dblist;          *dbdata = dblist;
   
 #else /* ISC_PLATFORM_USETHREADS */  
         /* if single threaded, just let user know we couldn't connect. */  
         if (PQstatus((PGconn *) dbi->dbconn) != CONNECTION_OK) {  
                 isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,  
                               DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,  
                               "Postgres driver failed to create database "  
                               "connection after 4 attempts");  
                 goto cleanup;  
         }  
   
         /*  
          * single threaded build can only use 1 db connection, return  
          * it via dbdata  
          */  
         *dbdata = dbi;  
   
 #endif /* ISC_PLATFORM_USETHREADS */  
   
         /* hey, we got through all of that ok, return success. */          /* hey, we got through all of that ok, return success. */
         return(ISC_R_SUCCESS);          return(ISC_R_SUCCESS);
   
  cleanup:   cleanup:
   
 #ifdef ISC_PLATFORM_USETHREADS  
         /*          /*
          * if multithreaded, we could fail because only 1 connection           * if multithreaded, we could fail because only 1 connection
          * couldn't be made.  We should cleanup the other successful           * couldn't be made.  We should cleanup the other successful
Line 1262  postgres_create(const char *dlzname, uns
Line 1205  postgres_create(const char *dlzname, uns
          */           */
         postgres_destroy_dblist(dblist);          postgres_destroy_dblist(dblist);
   
 #else /* ISC_PLATFORM_USETHREADS */  
         if (dbi != NULL)  
                 destroy_sqldbinstance(dbi);  
   
 #endif /* ISC_PLATFORM_USETHREADS */  
         return(ISC_R_FAILURE);          return(ISC_R_FAILURE);
 }  }
   
Line 1279  postgres_create(const char *dlzname, uns
Line 1217  postgres_create(const char *dlzname, uns
 static void  static void
 postgres_destroy(void *driverarg, void *dbdata)  postgres_destroy(void *driverarg, void *dbdata)
 {  {
   
 #ifdef ISC_PLATFORM_USETHREADS  
   
         UNUSED(driverarg);          UNUSED(driverarg);
         /* cleanup the list of DBI's */          /* cleanup the list of DBI's */
         postgres_destroy_dblist((db_list_t *) dbdata);          postgres_destroy_dblist((db_list_t *) dbdata);
   
 #else /* ISC_PLATFORM_USETHREADS */  
   
         dbinstance_t *dbi;  
   
         UNUSED(driverarg);  
   
         dbi = (dbinstance_t *) dbdata;  
   
         /* release DB connection */  
         if (dbi->dbconn != NULL)  
                 PQfinish((PGconn *) dbi->dbconn);  
   
         /* destroy single DB instance */  
         destroy_sqldbinstance(dbi);  
   
 #endif /* ISC_PLATFORM_USETHREADS */  
 }  }
   
 /* pointers to all our runtime methods. */  /* pointers to all our runtime methods. */

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

CVSweb <webmaster@jp.NetBSD.org>