rpma icon indicating copy to clipboard operation
rpma copied to clipboard

Example: handling a connection drop

Open osalyk opened this issue 4 years ago • 1 comments

Note: This example runs properly only on HW.

CLIENT

Perform all steps of Example 7 with changes:

parameters: path to the file being rewritten, drop_connection

/* defined log structure */ 
struct log { 
        char signature[LOG_SIGNATURE_SIZE]; 
        uint8_t lock; /* 1 - client writes, 0 - log free */ 
        /* last written data (aligned to RPMA_ATOMIC_WRITE_ALIGNMENT) */ 
        uint64_t used; 
        char data[LOG_DATA_SIZE]; 
}; 
function reconnect() 
{ 
        disconnect
        establish a new connection (several attempts may be needed, like FIO engines
                                    https://github.com/pmem/fio/blob/aof/engines/librpma_fio.c#L209 )
        rpma_read(used) 
        continue writing from reading used 
} 
rpma_read(lock) 
if (lock == 1) { 
        fprintf(stderr, “busy”); 
        disconnecting and closing the program 
} 
rpma_write_atomic (lock=1) 
… (example 07) 
if (drop_connection) { /* user specified parameter */ 
        reconnect() 
} 

ret = rpma_conn_completion_get();
if (ret && ret != RPMA_E_NO_COMPLETION)
	goto err;
if (ret == RPMA_E_NO_COMPLETION) {
        rpma_conn_completion_wait() 
        rpma_conn_completion_get() 
}
if (cmpl.op_status == IBV_WC_RETRY_EXC_ERR) { 
        ret = rpma_conn_next_event() 
        if (!ret && conn_event != RPMA_CONN_CLOSED) { 
                fprintf(stderr, 
                 	 "rpma_conn_next_event returned an unexpected event: %s\n", 
                	 rpma_utils_conn_event_2str(conn_event)); 
                disconnecting and closing the program 
         } 
         reconnect() 
} 
rpma_write_atomic (lock = 0) 
rpma_flush 
disconnect 

SERVER

Perform all steps of Example 7 with changes: parameters: drop_connection

after accept connection: 
if (drop_connection) {/* user specified parameter */ 
        sleep (5); 
        disconnect 
        if (lock == 1) { 
                create new connection 
        } 
} 

do { 
        wait for RPMA_CONN_CLOSED 
        disconnect 
        if (lock == 1) { 
                create new connection 
        } 
} while (lock != 0) 

print saved data 

osalyk avatar Apr 14 '21 09:04 osalyk

LGTM :+1:

ldorau avatar Apr 14 '21 14:04 ldorau