Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Example: handling a connection drop #995

Open
osalyk opened this issue Apr 14, 2021 · 1 comment
Open

Example: handling a connection drop #995

osalyk opened this issue Apr 14, 2021 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@osalyk
Copy link
Contributor

osalyk commented Apr 14, 2021

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 osalyk added the enhancement New feature or request label Apr 14, 2021
@ldorau
Copy link
Member

ldorau commented Apr 14, 2021

LGTM 👍

@janekmi janekmi added the good first issue Good for newcomers label Sep 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants