Proxy class for FS broker. More...
#include <Client.h>
Public Types | |
enum | { SHUTDOWN_FLAG_IMMEDIATE = 0x01 } |
Public Types inherited from Hypertable::Filesystem | |
enum | Flags : uint8_t { Flags::NONE =0, Flags::FLUSH =1, Flags::SYNC =2 } |
Enumeration type for append flags. More... | |
enum | OpenFlags { OPEN_FLAG_DIRECTIO = 0x00000001, OPEN_FLAG_OVERWRITE = 0x00000002, OPEN_FLAG_VERIFY_CHECKSUM = 0x00000004 } |
Public Member Functions | |
virtual | ~Client () |
Client (ConnectionManagerPtr &conn_manager_ptr, const sockaddr_in &addr, uint32_t timeout_ms) | |
Constructor with explicit values. More... | |
Client (ConnectionManagerPtr &conn_manager_ptr, PropertiesPtr &cfg) | |
Constructor with config var map. More... | |
Client (Comm *comm, const sockaddr_in &addr, uint32_t timeout_ms) | |
Constructor without connection manager. More... | |
Client (const String &host, int port, uint32_t timeout_ms) | |
Convenient contructor for dfs testing. More... | |
bool | wait_for_connection (uint32_t max_wait_ms) |
Waits up to max_wait_secs for a connection to be established with the FS broker. More... | |
void | open (const String &name, uint32_t flags, DispatchHandler *handler) override |
Opens a file asynchronously. More... | |
int | open (const String &name, uint32_t flags) override |
Opens a file. More... | |
int | open_buffered (const String &name, uint32_t flags, uint32_t buf_size, uint32_t outstanding, uint64_t start_offset=0, uint64_t end_offset=0) override |
Opens a file in buffered (readahead) mode. More... | |
void | decode_response_open (EventPtr &event, int32_t *fd) override |
Decodes the response from an open request. More... | |
void | create (const String &name, uint32_t flags, int32_t bufsz, int32_t replication, int64_t blksz, DispatchHandler *handler) override |
Creates a file asynchronously. More... | |
int | create (const String &name, uint32_t flags, int32_t bufsz, int32_t replication, int64_t blksz) override |
Creates a file. More... | |
void | decode_response_create (EventPtr &event, int32_t *fd) override |
Decodes the response from a create request. More... | |
void | close (int32_t fd, DispatchHandler *handler) override |
void | close (int32_t fd) override |
void | read (int32_t fd, size_t amount, DispatchHandler *handler) override |
size_t | read (int32_t fd, void *dst, size_t amount) override |
void | decode_response_read (EventPtr &event, const void **buffer, uint64_t *offset, uint32_t *length) override |
Decodes the response from a read request. More... | |
void | append (int32_t fd, StaticBuffer &buffer, Flags flags, DispatchHandler *handler) override |
size_t | append (int32_t fd, StaticBuffer &buffer, Flags flags=Flags::NONE) override |
void | decode_response_append (EventPtr &event, uint64_t *offset, uint32_t *length) override |
Decodes the response from an append request. More... | |
void | seek (int32_t fd, uint64_t offset, DispatchHandler *handler) override |
void | seek (int32_t fd, uint64_t offset) override |
void | remove (const String &name, DispatchHandler *handler) override |
Removes a file asynchronously. More... | |
void | remove (const String &name, bool force=true) override |
Removes a file. More... | |
void | length (const String &name, bool accurate, DispatchHandler *handler) override |
Gets the length of a file asynchronously. More... | |
int64_t | length (const String &name, bool accurate=true) override |
Gets the length of a file. More... | |
int64_t | decode_response_length (EventPtr &event) override |
Decodes the response from a length request. More... | |
void | pread (int32_t fd, size_t len, uint64_t offset, bool verify_checksum, DispatchHandler *handler) override |
size_t | pread (int32_t fd, void *dst, size_t len, uint64_t offset, bool verify_checksum) override |
void | decode_response_pread (EventPtr &event, const void **buffer, uint64_t *offset, uint32_t *length) override |
Decodes the response from a pread request. More... | |
void | mkdirs (const String &name, DispatchHandler *handler) override |
Creates a directory asynchronously. More... | |
void | mkdirs (const String &name) override |
Creates a directory. More... | |
void | flush (int32_t fd, DispatchHandler *handler) override |
void | flush (int32_t fd) override |
void | sync (int32_t fd) override |
void | rmdir (const String &name, DispatchHandler *handler) override |
Recursively removes a directory asynchronously. More... | |
void | rmdir (const String &name, bool force=true) override |
Recursively removes a directory. More... | |
void | readdir (const String &name, DispatchHandler *handler) override |
Obtains a listing of all files in a directory asynchronously. More... | |
void | readdir (const String &name, std::vector< Dirent > &listing) override |
Obtains a listing of all files in a directory. More... | |
void | decode_response_readdir (EventPtr &event, std::vector< Dirent > &listing) override |
Decodes the response from a readdir request. More... | |
void | exists (const String &name, DispatchHandler *handler) override |
Determines if a file exists asynchronously. More... | |
bool | exists (const String &name) override |
Determines if a file exists. More... | |
bool | decode_response_exists (EventPtr &event) override |
Decodes the response from an exists request. More... | |
void | rename (const String &src, const String &dst, DispatchHandler *handler) override |
Rename a path asynchronously. More... | |
void | rename (const String &src, const String &dst) override |
Rename a path. More... | |
void | status (Status &status, Timer *timer=0) override |
Check status of filesystem. More... | |
void | decode_response_status (EventPtr &event, Status &status) override |
Decodes the response from an status request. More... | |
void | debug (int32_t command, StaticBuffer &serialized_parameters) override |
Invokes debug request asynchronously. More... | |
void | debug (int32_t command, StaticBuffer &serialized_parameters, DispatchHandler *handler) override |
Invokes debug request. More... | |
void | shutdown (uint16_t flags, DispatchHandler *handler) |
Shuts down the FS broker. More... | |
uint32_t | get_timeout () |
Gets the configured request timeout value. More... | |
Public Member Functions inherited from Hypertable::Filesystem | |
virtual | ~Filesystem () |
virtual void | close (int fd, DispatchHandler *handler)=0 |
Closes a file asynchronously. More... | |
virtual void | close (int fd)=0 |
Closes a file. More... | |
virtual void | read (int fd, size_t len, DispatchHandler *handler)=0 |
Reads data from a file at the current position asynchronously. More... | |
virtual size_t | read (int fd, void *dst, size_t len)=0 |
Reads data from a file at the current position. More... | |
virtual void | append (int fd, StaticBuffer &buffer, Flags flags, DispatchHandler *handler)=0 |
Appends data to a file asynchronously. More... | |
virtual size_t | append (int fd, StaticBuffer &buffer, Flags flags=Flags::NONE)=0 |
Appends data to a file. More... | |
virtual void | seek (int fd, uint64_t offset, DispatchHandler *handler)=0 |
Seeks current file position asynchronously. More... | |
virtual void | seek (int fd, uint64_t offset)=0 |
Seeks current file position. More... | |
virtual void | pread (int fd, size_t amount, uint64_t offset, bool verify_checksum, DispatchHandler *handler)=0 |
Reads data from a file at the specified position asynchronously. More... | |
virtual size_t | pread (int fd, void *dst, size_t len, uint64_t offset, bool verify_checksum=true)=0 |
Reads data from a file at the specified position. More... | |
virtual void | flush (int fd, DispatchHandler *handler)=0 |
Flushes a file asynchronously. More... | |
virtual void | flush (int fd)=0 |
Flushes a file. More... | |
virtual void | sync (int fd)=0 |
Syncs a file. More... | |
Private Member Functions | |
void | send_message (CommBufPtr &cbuf, DispatchHandler *handler, Timer *timer=0) |
Sends a message to the FS broker. More... | |
Private Attributes | |
std::mutex | m_mutex |
Comm * | m_comm |
ConnectionManagerPtr | m_conn_mgr |
InetAddr | m_addr |
uint32_t | m_timeout_ms |
std::unordered_map< uint32_t, ClientBufferedReaderHandler * > | m_buffered_reader_map |
Additional Inherited Members | |
Static Public Member Functions inherited from Hypertable::Filesystem | |
static int | decode_response (EventPtr &event) |
Decodes the response from an request that only returns an error code. More... | |
static String | dirname (String name, char separator= '/') |
A posix-compliant dirname() which strips the last component from a file name. More... | |
static String | basename (String name, char separator= '/') |
A posix-compliant basename() which strips directory names from a filename. More... | |
Proxy class for FS broker.
As specified in the general contract for a Filesystem, commands that operate on the same file descriptor are serialized by the underlying filesystem. In other words, if you issue three asynchronous commands, they will get carried out and their responses will come back in the same order in which they were issued.
|
virtual |
this causes deadlock in RangeServer shutdown if (m_conn_mgr) m_conn_mgr->remove(m_addr);
Client::Client | ( | ConnectionManagerPtr & | conn_manager_ptr, |
const sockaddr_in & | addr, | ||
uint32_t | timeout_ms | ||
) |
Constructor with explicit values.
Connects to the FS broker at the address given by the addr argument and uses the timeout argument for the request timeout values.
conn_manager_ptr | smart pointer to connection manager |
addr | address of FS broker to connect to |
timeout_ms | timeout value in milliseconds to use in requests |
Client::Client | ( | ConnectionManagerPtr & | conn_manager_ptr, |
PropertiesPtr & | cfg | ||
) |
Constructor with config var map.
The following properties are read to determine the location of the broker and the request timeout value:
FsBroker.port FsBroker.host FsBroker.timeout
conn_manager_ptr | smart pointer to connection manager |
cfg | config variables map |
Client::Client | ( | Comm * | comm, |
const sockaddr_in & | addr, | ||
uint32_t | timeout_ms | ||
) |
Client::Client | ( | const String & | host, |
int | port, | ||
uint32_t | timeout_ms | ||
) |
|
override |
|
override |
|
override |
|
overridevirtual |
Creates a file asynchronously.
Issues a create file request with various create mode parameters. The caller will get notified of successful completion or error via the given dispatch handler. It is up to the caller to deserialize the returned file descriptor from the MESSAGE event object.
name | Absolute path name of file to open |
flags | Open flags (OPEN_FLAG_DIRECTIO or OPEN_FLAG_OVERWRITE) |
bufsz | Buffer size to use for the underlying FS |
replication | Replication factor to use for this file |
blksz | Block size to use for the underlying FS |
handler | The dispatch handler which will handle the reply |
Implements Hypertable::Filesystem.
|
overridevirtual |
Creates a file.
Issues a create file request and waits for completion
name | Absolute path name of file to open |
flags | Open flags (OPEN_FLAG_DIRECTIO or OPEN_FLAG_OVERWRITE) |
bufsz | Buffer size to use for the underlying FS |
replication | Replication factor to use for this file |
blksz | Block size to use for the underlying FS |
Implements Hypertable::Filesystem.
|
overridevirtual |
Invokes debug request asynchronously.
command | debug command identifier |
serialized_parameters | command specific serialized parameters |
Implements Hypertable::Filesystem.
|
overridevirtual |
Invokes debug request.
command | The debug command identifier |
serialized_parameters | The command specific serialized parameters |
handler | The dispatch/callback handler |
Implements Hypertable::Filesystem.
|
overridevirtual |
Decodes the response from an append request.
event | A reference to the response event |
offset | Address of offset variable |
length | Address of length variable |
Implements Hypertable::Filesystem.
|
overridevirtual |
Decodes the response from a create request.
event | reference to response event |
fd | Address of variable to hold file descriptor |
Implements Hypertable::Filesystem.
|
overridevirtual |
Decodes the response from an exists request.
event | A reference to the response event |
Implements Hypertable::Filesystem.
|
overridevirtual |
Decodes the response from a length request.
event | Reference to response event |
Implements Hypertable::Filesystem.
|
overridevirtual |
Decodes the response from an open request.
event | reference to response event |
fd | Address of variable to hold file descriptor |
Implements Hypertable::Filesystem.
|
overridevirtual |
Decodes the response from a pread request.
event | A reference to the response event |
buffer | Address of buffer pointer |
offset | Address of offset variable |
length | Address of length variable |
Implements Hypertable::Filesystem.
|
overridevirtual |
Decodes the response from a read request.
event | A reference to the response event |
buffer | Address of buffer pointer |
offset | Address of offset variable |
length | Address of length variable |
Implements Hypertable::Filesystem.
|
overridevirtual |
Decodes the response from a readdir request.
event | A reference to the response event |
listing | Reference to output vector of Dirent objects |
Implements Hypertable::Filesystem.
Decodes the response from an status request.
event | Reference to response event |
status | Reference to status information output parameter |
Implements Hypertable::Filesystem.
|
overridevirtual |
Determines if a file exists asynchronously.
Issues an exists request. The caller will get notified of successful completion or error via the given dispatch handler.
name | The absolute pathname of file |
handler | The dispatch handler |
Implements Hypertable::Filesystem.
|
overridevirtual |
Determines if a file exists.
name | The absolute pathname of the file |
Implements Hypertable::Filesystem.
|
override |
|
inline |
|
overridevirtual |
Gets the length of a file asynchronously.
Issues a length request. The caller will get notified of successful completion or error via the given dispatch handler.
name | The absolute pathname of file |
accurate | Whether the accurate or an estimated file length is required (an hdfs performance optimization) |
handler | The dispatch handler |
Implements Hypertable::Filesystem.
|
overridevirtual |
Gets the length of a file.
Issues a length request and waits for it to complete.
name | The absolute pathname of file |
accurate | Whether the accurate or an estimated file length is required (an hdfs performance optimization) |
Implements Hypertable::Filesystem.
|
overridevirtual |
Creates a directory asynchronously.
Issues a mkdirs request which creates a directory, including all its missing parents. The caller will get notified of successful completion or error via the given dispatch handler.
name | The absolute pathname of directory to create |
handler | The dispatch handler |
Implements Hypertable::Filesystem.
|
overridevirtual |
Creates a directory.
Issues a mkdirs request which creates a directory, including all its missing parents, and waits for it to complete.
name | The absolute pathname of the directory to create |
Implements Hypertable::Filesystem.
|
overridevirtual |
Opens a file asynchronously.
Issues an open file request. The caller will get notified of successful completion or error via the given dispatch handler. It is up to the caller to deserialize the returned file descriptor from the MESSAGE event object.
name | Absolute path name of file to open |
flags | Open flags (OPEN_FLAG_DIRECTIO or 0) |
handler | The dispatch handler which will handle the reply |
Implements Hypertable::Filesystem.
|
overridevirtual |
Opens a file.
Issues an open file request and waits for it to complete.
name | Absolute path name of file to open |
flags | Open flags (OPEN_FLAG_DIRECTIO or 0) |
Implements Hypertable::Filesystem.
|
overridevirtual |
Opens a file in buffered (readahead) mode.
Issues an open file request and waits for it to complete. Turns on readahead mode so that data is prefetched.
name | Absolute path name of file to open |
flags | Open flags (OPEN_FLAG_DIRECTIO or 0) |
buf_size | Read ahead buffer size |
outstanding | Maximum number of outstanding reads |
start_offset | Starting read offset |
end_offset | Ending read offset |
Implements Hypertable::Filesystem.
|
override |
|
override |
|
override |
|
override |
|
overridevirtual |
Obtains a listing of all files in a directory asynchronously.
Issues a readdir request. The caller will get notified of successful completion or error via the given dispatch handler.
name | The absolute pathname of directory |
handler | The dispatch handler |
Implements Hypertable::Filesystem.
Obtains a listing of all files in a directory.
Issues a readdir request and waits for it to complete.
name | Absolute pathname of directory |
listing | Reference to output vector of Dirent objects for each entry |
Implements Hypertable::Filesystem.
|
overridevirtual |
Removes a file asynchronously.
Issues a remove request. The caller will get notified of successful completion or error via the given dispatch handler.
name | The absolute pathname of file to delete |
handler | The dispatch handler |
Implements Hypertable::Filesystem.
|
overridevirtual |
Removes a file.
Issues a remove request and waits for it to complete.
name | The absolute pathname of file to delete |
force | If true then ignore non-existence error |
Implements Hypertable::Filesystem.
|
overridevirtual |
Rename a path asynchronously.
src | The source path |
dst | The destination path |
handler | The dispatch/callback handler |
Implements Hypertable::Filesystem.
Rename a path.
src | The source path |
dst | The destination path |
Implements Hypertable::Filesystem.
|
overridevirtual |
Recursively removes a directory asynchronously.
Issues a rmdir request. The caller will get notified of successful completion or error via the given dispatch handler.
name | The absolute pathname of directory to remove |
handler | The dispatch handler |
Implements Hypertable::Filesystem.
|
overridevirtual |
Recursively removes a directory.
Issues a rmdir request and waits for it to complete.
name | The absolute pathname of directory to remove |
force | If true then don't throw an error if file does not exist |
Implements Hypertable::Filesystem.
|
override |
|
override |
|
private |
void Client::shutdown | ( | uint16_t | flags, |
DispatchHandler * | handler | ||
) |
Shuts down the FS broker.
Issues a shutdown command to the FS broker. If the flag is set to SHUTDOWN_FLAG_IMMEDIATE, then the broker will call exit(0) directly from the I/O reactor thread. Otherwise, a shutdown command will get added to the broker's application queue, allowing the shutdown to be handled more gracefully.
flags | controls how broker gets shut down |
handler | response handler |
Check status of filesystem.
status | Status output |
timer | Deadline timer |
Implements Hypertable::Filesystem.
|
inline |
|
private |
|
private |
|
private |
|
private |