tabled: auto ports, except replication
PATCH 1/1 tabled: auto ports, except replication
This patch adds the automatic listening port feature to tabled in the same way it was done in CLD and Chunk. It turns auto ports on, too.
The patch also starts making use of auto ports in CLD and Chunk. Thus, our build requires this support in the installed versions of them.
There's still an issue of the DB4 replication using a fixed port.
Signed-off-by Pete Zaitcev <[email protected]>
include/httpstor.h +3 -2
@@ -27,6 +27,7 @@struct httpstor_client {CURL *curl; +char *acc;char *host;char *user;char *key;
@@ -71,8 +72,8 @@ extern void httpstor_free_bucket(struct httpstor_bucket *buck);extern void httpstor_free_object (struct httpstor_object *obj);extern void httpstor_free_keylist (struct httpstor_keylist *keylist); -extern struct httpstor_client *httpstor_new (const char *service_host, -const char *user,const char *secret_key); +extern struct httpstor_client *httpstor_new (const char *service_acc, +const char *service_host,const char *user,const char *secret_key);extern bool httpstor_add_bucket (struct httpstor_client *httpstor,const char *name);extern bool httpstor_del_bucket (struct httpstor_client *httpstor,const char *name);
include/httputil.h +3 -0
@@ -101,6 +101,9 @@ extern struct uri *uri_parse(struct uri *uri_dest, char *uri_src_text);extern int field_unescape (char *s,int s_len);extern char *field_escape (char *signed_str,unsigned char mask); +/* readport.c */ +extern int tb_readport (const char *fname,char *buf,size_t len); +static inline bool http11 (struct http_req *req) {if (req->major >1 )
lib/Makefile.am +1 -1
@@ -4,7 +4,7 @@ INCLUDES = -I$(top_srcdir)/include \ noinst_LIBRARIES = libhttputil.a libtdb.a -libhttputil_a_SOURCES = httputil.c uri.c +libhttputil_a_SOURCES = httputil.c uri.c readport.c libtdb_a_SOURCES = tdb.c
lib/httpstor.c +21 -10
@@ -42,14 +42,21 @@ void httpstor_free(struct httpstor_client *httpstor) {if (httpstor->curl)curl_easy_cleanup (httpstor->curl); +free (httpstor->acc);free (httpstor->host);free (httpstor->user);free (httpstor->key);free (httpstor); } -struct httpstor_client *httpstor_new (const char *service_host, -const char *user,const char *secret_key) +/* +* The service accessor is a "host:port" string that gets resolved to IP +* address and then create a TCP connection to the server. The service host, +* however, is used to form the "Host: host" HTTP header. The host of the +* accessor should be the same on the sane installations, but whatever. +*/ +struct httpstor_client *httpstor_new (const char *service_acc, +const char *service_host,const char *user,const char *secret_key) {struct httpstor_client *httpstor;
@@ -57,10 +64,11 @@ struct httpstor_client *httpstor_new(const char *service_host,if (!httpstor)return NULL ; + httpstor->acc =strdup (service_acc); httpstor->host =strdup (service_host); httpstor->user =strdup (user); httpstor->key =strdup (secret_key); -if (!httpstor->host || !httpstor->user || !httpstor->key) +if (!httpstor->acc || !httpstor->host || !httpstor->user || !httpstor->key) goto err_out;if (curl_global_init (CURL_GLOBAL_ALL ))
@@ -170,7 +178,7 @@ next:struct httpstor_blist *httpstor_list_buckets (struct httpstor_client *httpstor) {struct http_req req; -char datestr[80 ], timestr[64 ], hmac[64 ], auth[128 ], host[80 ]; +char datestr[80 ], timestr[64 ], hmac[64 ], auth[128 ], host[80 ], url[80 ];struct curl_slist *headers =NULL ;struct httpstor_blist *blist;xmlDocPtr doc;
@@ -200,10 +208,12 @@ struct httpstor_blist *httpstor_list_buckets(struct httpstor_client *httpstor) headers =curl_slist_append (headers, datestr); headers =curl_slist_append (headers, auth); +snprintf (url,sizeof (url),"http://%s/" , httpstor->acc); +curl_easy_reset (httpstor->curl);if (httpstor->verbose)curl_easy_setopt (httpstor->curl,CURLOPT_VERBOSE ,1 ); -curl_easy_setopt (httpstor->curl,CURLOPT_URL ,"http://localhost:18080/" ); +curl_easy_setopt (httpstor->curl,CURLOPT_URL , url);curl_easy_setopt (httpstor->curl,CURLOPT_HTTPHEADER , headers);curl_easy_setopt (httpstor->curl,CURLOPT_ENCODING ,"" );curl_easy_setopt (httpstor->curl,CURLOPT_FAILONERROR ,1 );
@@ -312,7 +322,7 @@ static bool __httpstor_ad_bucket(struct httpstor_client *httpstor, const char *nsprintf (auth,"Authorization: AWS %s:%s" , httpstor->user, hmac);sprintf (host,"Host: %s" , httpstor->host); -sprintf (url,"http://localhost:18080/%s/" , name); +snprintf (url,sizeof (url),"http://%s/%s/" , httpstor->acc, name); headers =curl_slist_append (headers, host); headers =curl_slist_append (headers, datestr);
@@ -371,7 +381,7 @@ bool httpstor_get(struct httpstor_client *httpstor, const char *bucket, const chsprintf (auth,"Authorization: AWS %s:%s" , httpstor->user, hmac);sprintf (host,"Host: %s" , httpstor->host); -sprintf (url,"http://localhost:18080%s" , orig_path); +snprintf (url,sizeof (url),"http://%s%s" , httpstor->acc, orig_path); headers =curl_slist_append (headers, host); headers =curl_slist_append (headers, datestr);
@@ -450,7 +460,7 @@ bool httpstor_put(struct httpstor_client *httpstor, const char *bucket, const chsprintf (auth,"Authorization: AWS %s:%s" , httpstor->user, hmac);sprintf (host,"Host: %s" , httpstor->host); -sprintf (url,"http://localhost:18080%s" , orig_path); +snprintf (url,sizeof (url),"http://%s%s" , httpstor->acc, orig_path); headers =curl_slist_append (headers, host); headers =curl_slist_append (headers, datestr);
@@ -541,7 +551,7 @@ bool httpstor_del(struct httpstor_client *httpstor, const char *bucket, const chsprintf (auth,"Authorization: AWS %s:%s" , httpstor->user, hmac);sprintf (host,"Host: %s" , httpstor->host); -sprintf (url,"http://localhost:18080%s" , orig_path); +snprintf (url,sizeof (url),"http://%s%s" , httpstor->acc, orig_path); headers =curl_slist_append (headers, host); headers =curl_slist_append (headers, datestr);
@@ -748,7 +758,8 @@ struct httpstor_keylist *httpstor_keys(struct httpstor_client *httpstor, const c goto err_out; } - url =g_string_append (url,"http://localhost:18080" ); + url =g_string_append (url,"http://" ); + url =g_string_append (url, httpstor->acc); url =g_string_append (url, orig_path);if (prefix)
server/config.c +84 -17
141 lines not on this page · raw message
server/server.c +139 -41
212 lines not on this page · raw message
server/tabled.h +2 -0
@@ -199,6 +199,7 @@ struct listen_cfg {/* bool encrypt; */ /* char *host; */ char *port; +char *port_file; };struct server {
@@ -210,6 +211,7 @@ struct server {char *tdb_dir;/* TDB metadata database dir */ char *pid_file;/* PID file */ char *port;/* bind port */ +char *port_file;char *chunk_user;/* username for stc_new */ char *chunk_key;/* key for stc_new */ unsigned short rep_port;/* db4 replication port */
test/Makefile.am +2 -0
@@ -35,4 +35,6 @@ basic_bucket_LDADD = $(TESTLDADD) basic_object_LDADD = $(TESTLDADD) it_works_LDADD = $(TESTLDADD) +wait_for_listen_LDADD = ../lib/libhttputil.a + TESTS_ENVIRONMENT=top_srcdir=$(top_srcdir)
test/basic-bucket.c +7 -1
@@ -21,6 +21,7 @@#include <string.h> #include <locale.h> #include <httpstor.h> +#include <httputil.h> #include "test.h" int main (int argc,char *argv[])
@@ -29,10 +30,15 @@ int main(int argc, char *argv[])struct httpstor_blist *blist;struct httpstor_bucket *buck;bool rcb; +char accbuf[80 ]; +int rc;setlocale (LC_ALL ,"C" ); - httpstor =httpstor_new (TEST_HOST ,TEST_USER ,TEST_USER_KEY ); + rc =tb_readport (TEST_FILE_TB , accbuf,sizeof (accbuf)); +OK (rc >0 ); + + httpstor =httpstor_new (accbuf,TEST_HOST ,TEST_USER ,TEST_USER_KEY );OK (httpstor);/* make sure bucket list is empty */
test/basic-object.c +7 -1
@@ -21,11 +21,14 @@#include <string.h> #include <locale.h> #include <httpstor.h> +#include <httputil.h> #include "test.h" int main (int argc,char *argv[]) {struct httpstor_client *httpstor; +char accbuf[80 ]; +int rc;bool rcb;char val[] ="my first value" ;char key[] ="my first key" ;
@@ -34,7 +37,10 @@ int main(int argc, char *argv[])setlocale (LC_ALL ,"C" ); - httpstor =httpstor_new (TEST_HOST ,TEST_USER ,TEST_USER_KEY ); + rc =tb_readport (TEST_FILE_TB , accbuf,sizeof (accbuf)); +OK (rc >0 ); + + httpstor =httpstor_new (accbuf,TEST_HOST ,TEST_USER ,TEST_USER_KEY );OK (httpstor);/* add bucket */
test/chunkd-test.conf +2 -7
@@ -1,16 +1,11 @@ -<!-- - Ports not to use: - 82 -- too low for non-root - 8082 -- installed chunkd may use it - --> <Listen> - <Port>18082</Port> + <PortFile>/dev/null</PortFile> </Listen> <PID>chunkd.pid</PID> <Path>data/chunk</Path> <NID>1</NID> <CLD> - <Port>18081</Port> + <PortFile>cld.port</PortFile> <Host>localhost</Host> </CLD>
test/it-works.c +7 -1
@@ -21,16 +21,22 @@#include <string.h> #include <locale.h> #include <httpstor.h> +#include <httputil.h> #include "test.h" int main (int argc,char *argv[]) {struct httpstor_client *httpstor;struct httpstor_blist *blist; +char accbuf[80 ]; +int rc;setlocale (LC_ALL ,"C" ); - httpstor =httpstor_new (TEST_HOST ,TEST_USER ,TEST_USER_KEY ); + rc =tb_readport (TEST_FILE_TB , accbuf,sizeof (accbuf)); +OK (rc >0 ); + + httpstor =httpstor_new (accbuf,TEST_HOST ,TEST_USER ,TEST_USER_KEY );OK (httpstor); blist =httpstor_list_buckets (httpstor);
test/start-daemon +1 -1
@@ -17,7 +17,7 @@ then fi # May be different on Solaris... like /usr/libexec or such. -cld -d data/cld -P cld.pid -p 18081 -E +cld -d data/cld -P cld.pid --port-file=cld.port -E chunkd -C $top_srcdir/test/chunkd-test.conf -E ../server/tabled -C $top_srcdir/test/tabled-test.conf -E -D
test/stop-daemon +2 -0
@@ -19,6 +19,8 @@ killpid () { return 1 } +rm -f cld.port tabled.acc + ret=0 if [ ! -f tabled.pid ]
test/tabled-test.conf +2 -2
@@ -1,12 +1,12 @@ <PID>tabled.pid</PID> <ForceHost>localhost.localdomain</ForceHost> -<Listen><Port>18080</Port></Listen> +<Listen><PortFile>tabled.acc</PortFile></Listen> <TDB>data/tdb</TDB> <TDBRepPort>18083</TDBRepPort> <CLD> - <Port>18081</Port> + <PortFile>cld.port</PortFile> <Host>localhost</Host> </CLD>
test/test.h +2 -0
@@ -27,6 +27,8 @@#define TEST_USER "testuser"#define TEST_USER_KEY "testpw" +#define TEST_FILE_TB "tabled.acc" +#define OK (expr) \ do { \ if (!(expr)) { \
test/wait-for-listen.c +34 -6
@@ -11,6 +11,8 @@#include <time.h> #include <unistd.h> #include <netdb.h> +#include <httputil.h> +#include "test.h" #define ADDRSIZE 24/* Enough for IPv6, including port. */
@@ -62,17 +64,43 @@ int main() {struct server_node snode, *sn = &snode;time_t start_time; +const static char accname[] =TEST_FILE_TB ; +char accbuf[80 ]; +char *s; +int cnt;int sfd;int rc; -/* -* We hardcode host and port because we don't know an easy way -* to pass parameters to tests. -*/ + cnt =0 ; +for (;;) { + rc =tb_readport (accname, accbuf,sizeof (accbuf)); +if (rc >0 ) +break ; +if (++cnt >=5 ) {/* should not take long */ +if (rc ==0 ) { +fprintf (stderr,"Nothing to read in %s\n" , + accname); +exit (1 ); + } +if (rc <0 ) { +fprintf (stderr,"Failed to read %s: %s\n" , + accname,strerror (-rc)); +exit (1 ); + } + } +sleep (1 ); + } + + s =strchr (accbuf,':' ); +if (!s) + s ="80" ; +else + *s++ =0 ; +memset (sn,0 ,sizeof (struct server_node )); -if (node_resolve (sn,"localhost" ,"18080" ) !=0 ) { +if (node_resolve (sn, accbuf, s) !=0 ) {fprintf (stderr, -"Unable to resolve host localhost port 18080\n" ); +"Unable to resolve host %s port %s\n" , accbuf, s);exit (1 ); }
Quoted 1 line · Jeff Garzik
readport.cwould help :)
That's it, I'm not using git to make patches anymore. Too confusing.
-- Pete