You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2019/08/04 05:19:29 UTC

[GitHub] [incubator-shardingsphere] wwanix opened a new issue #2807: sharding-proxy seemed not work well when C language based on API of libpq.so

wwanix opened a new issue #2807: sharding-proxy seemed not work well when C language based on API of libpq.so
URL: https://github.com/apache/incubator-shardingsphere/issues/2807
 
 
   ## Bug Report
   
   ### Which version of ShardingSphere did you use?
   4.0.0-RC1
   
   ### Which project did you use? Sharding-JDBC or Sharding-Proxy?
   Sharding-Proxy
   
   ### Expected behavior
   C program invoke functions supplyed by libpq.so like PQconnectdb, PQprepare, PQexecPrepared, PQntuples, etc, it should run normally and return number of affected rows.
   
   ### Actual behavior
   The program just hang in there and the log of sharding-proxy shows like below:
   
   [INFO ] 12:38:07.949 [epollEventLoopGroup-2-1] i.n.handler.logging.LoggingHandler - [id: 0x4cb31b9f, L:/0.0.0.0:3307] READ: [id: 0xd740bb9c, L:/127.0.0.1:3307 - R:/127.0.0.1:14467]
   [INFO ] 12:38:07.949 [epollEventLoopGroup-2-1] i.n.handler.logging.LoggingHandler - [id: 0x4cb31b9f, L:/0.0.0.0:3307] READ COMPLETE
   
   and there are nothing output in postgres log file.
   
   ### Reason analyze (If you can)
   It seems that communication packages is diff between using the real postgresql and sharding-proxy when catch the packages by using dumptcp. 
   
   BTW, it is noticed that psql works well in most of time.
   
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
   SQL: 
   select trans_id from cfg_trans_access
   
   sharding rule configuration:
   schemaName: sharding_db
   #
   dataSources:
     ds_0:
       url: jdbc:postgresql://127.0.0.1:12341/ecifpub
       username: ecifpub
       password: ECIF*eb2019
       connectionTimeoutMilliseconds: 30000
       idleTimeoutMilliseconds: 60000
       maxLifetimeMilliseconds: 1800000
       maxPoolSize: 50
     ds_1:
       url: jdbc:postgresql://127.0.0.1:12342/ecifpub
       username: ecifpub
       password: ECIF*eb2019
       connectionTimeoutMilliseconds: 30000
       idleTimeoutMilliseconds: 60000
       maxLifetimeMilliseconds: 1800000
       maxPoolSize: 50
   
   shardingRule:
     tables:
       cfg_trans_access:
         actualDataNodes: ds_${0..1}.cfg_trans_access
         tableStrategy:
           none:
   
   ### Example codes for reproduce this issue (such as a github link).
   #include <stdlib.h>
   #include <stdio.h>
   #include <string.h>
   #include <libpq-fe.h> 
   
   main(int argc, char *argv[])
   {
       int iResp, RespCode, i;
       int DataLength, FieldNum, RowCount; 
       int *paramLengths, *paramFormats;
       char cSqlstmt[1024*5], data_type[128];
       char sConnString[128+1]={0};
       char sURL[128+1] = {0};
       char UserName[80];
       char stmtName[128+1] = {0};
       PGconn *conn=NULL;
       PGresult *res=NULL;
       char **param_values;
       char *DataBuf;
   
       memset(UserName, 0, sizeof(UserName));
       if(argc != 4)
       {
           printf("Usage:\n");
           printf("      dbact <dbuser> <dbpass> <db@host:port>\n");
           exit(0);
       } 
       strcpy( sURL,argv[3]);
       char *pDB = strtok( sURL,"@" );
       char *pHost = strtok( NULL,":" );
       char *pPort = strtok( NULL,":" );
       if( pDB == NULL || pHost == NULL ||pPort == NULL ){
           printf("argv[3] must be <db@host:port>\n");
           exit(0);
       } 	
       strcpy(UserName, argv[1]);
   
       sprintf(sConnString,"host=%s port=%s dbname=%s user=%s password=%s", pHost, pPort, pDB, UserName, argv[2]);
       fprintf(stderr, "URL=[%s]\n", sConnString);
   
       conn = PQconnectdb(sConnString);
       if (!conn || PQstatus(conn) != CONNECTION_OK) {
           fprintf(stderr, "CONNECT FAILED--%d:%s\n", PQstatus(conn), PQerrorMessage(conn));
   	PQfinish(conn);
   	conn = NULL;
           exit(-1);
       }
   
       sprintf(cSqlstmt, "select trans_id from cfg_trans_access");
       res = PQprepare(conn, stmtName, cSqlstmt, 0, NULL);
       if(PQresultStatus(res) != PGRES_COMMAND_OK){
   	fprintf(stderr, "PQprepare Failed==%d:%s\n", PQresStatus(PQresultStatus(res)),PQresultErrorMessage(res));
   	PQfinish(conn);
   	conn = NULL;
           exit(-1);
       }
   
       res = PQexecPrepared(conn, stmtName, 0, (const char * const*)param_values, paramLengths, paramFormats, 0);
       if(PQresultStatus(res) != PGRES_TUPLES_OK){
   	fprintf(stderr, "PQexecPrepared Failed==%d:%s\n", PQresStatus(PQresultStatus(res)),PQresultErrorMessage(res));
   	PQfinish(conn);
   	conn = NULL;
           exit(-1);
       }
       RowCount = PQntuples(res);
   
       fprintf(stderr, "%d rows affected.\n", RowCount);
   
       PQfinish(conn);
       conn = NULL;
       exit(0);
   }
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services