@@ -542,6 +542,7 @@ bool MySQL_Session::handler_special_queries(PtrSize_t *pkt) {
542
542
return false ;
543
543
}
544
544
545
+ #define NEXT_IMMEDIATE (new_st ) do { set_status (new_st); goto handler_again; } while (0 )
545
546
546
547
int MySQL_Session::handler () {
547
548
bool wrong_pass=false ;
@@ -654,6 +655,13 @@ int MySQL_Session::handler() {
654
655
current_hostgroup=default_hostgroup;
655
656
}
656
657
proxy_debug (PROXY_DEBUG_MYSQL_CONNECTION, 5 , " Statuses: WAITING_CLIENT_DATA - STATE_SLEEP\n " );
658
+ if (session_fast_forward==true ) { // if it is fast forward
659
+ mybe=find_or_create_backend (current_hostgroup); // set a backend
660
+ mybe->server_myds ->reinit_queues (); // reinitialize the queues in the myds . By default, they are not active
661
+ mybe->server_myds ->PSarrayOUT ->add (pkt.ptr , pkt.size ); // move the first packet
662
+ previous_status.push (FAST_FORWARD); // next status will be FAST_FORWARD . Now we need a connection
663
+ NEXT_IMMEDIATE (CONNECTING_SERVER); // we create a connection . next status will be FAST_FORWARD
664
+ }
657
665
// unsigned char c;
658
666
c=*((unsigned char *)pkt.ptr +sizeof (mysql_hdr));
659
667
switch ((enum_mysql_command)c) {
@@ -824,14 +832,21 @@ int MySQL_Session::handler() {
824
832
}
825
833
826
834
827
- #define NEXT_IMMEDIATE (new_st ) do { set_status (new_st); goto handler_again; } while (0 )
828
835
829
836
handler_again:
830
837
831
838
switch (status) {
832
839
case FAST_FORWARD:
833
- fprintf (stderr," FAST_FORWARD\n " );
834
- // FIXME: to implement
840
+ if (mybe->server_myds ->mypolls ==NULL ) {
841
+ // register the mysql_data_stream
842
+ thread->mypolls .add (POLLIN|POLLOUT, mybe->server_myds ->fd , mybe->server_myds , thread->curtime );
843
+ }
844
+ // copy all packets from backend to frontend
845
+ for (unsigned int k=0 ; k < mybe->server_myds ->PSarrayIN ->len ; k++) {
846
+ PtrSize_t pkt;
847
+ mybe->server_myds ->PSarrayIN ->remove_index (0 ,&pkt);
848
+ client_myds->PSarrayOUT ->add (pkt.ptr , pkt.size );
849
+ }
835
850
break ;
836
851
case CONNECTING_CLIENT:
837
852
// fprintf(stderr,"CONNECTING_CLIENT\n");
@@ -1421,6 +1436,11 @@ int MySQL_Session::handler() {
1421
1436
st=previous_status.top ();
1422
1437
previous_status.pop ();
1423
1438
myds->wait_until =0 ;
1439
+ if (session_fast_forward==true ) {
1440
+ // we have a successful connection and session_fast_forward enabled
1441
+ // set DSS=STATE_SLEEP or it will believe it have to use MARIADB client library
1442
+ myds->DSS =STATE_SLEEP;
1443
+ }
1424
1444
NEXT_IMMEDIATE (st);
1425
1445
break ;
1426
1446
case -1 :
@@ -1923,6 +1943,7 @@ void MySQL_Session::handler___client_DSS_QUERY_SENT___server_DSS_NOT_INITIALIZED
1923
1943
mybe->server_myds ->DSS =STATE_READY;
1924
1944
if (session_fast_forward==true ) {
1925
1945
status=FAST_FORWARD;
1946
+ mybe->server_myds ->myconn ->reusable =false ; // the connection cannot be usable anymore
1926
1947
}
1927
1948
}
1928
1949
}
0 commit comments