NCCLOUD  0.1
Public Member Functions | Static Public Member Functions | Protected Member Functions
Coding Class Reference

Abstract base class for coding modules. More...

#include <coding.h>

Public Member Functions

virtual int encode_file (std::string &dstdir, std::string &srcdir, std::string &filename)=0
 Encode a file at srcdir/filename into chunks stored under dstdir.
virtual int decode_file (std::string &dst, std::string &srcdir, std::string &filename, std::vector< int > &chunk_indices)=0
 Reconstruct a file from chunks under srcdir into dst.
virtual int repair_file_preprocess (std::string &srcdir, std::string &filename, std::vector< int > &erasures, std::vector< int > &chunks_to_retrieve)=0
 Setup repair and inform the user which chunks to retrieve for use in repair.
virtual int repair_file (std::string &dstdir, std::string &srcdir, std::string &filename)=0
 Generate new chunks to replace failed chunks.
virtual int getn (void)=0
 Return the total number of nodes.
virtual int getk (void)=0
 Return the number of nodes required to reconstruct data.
virtual int nodeid (int index)=0
 Return ID of the node where a specified chunk resides.
virtual int chunks_per_node (void)=0
 Return the number of chunks per node.
virtual int chunks_on_node (int node, std::vector< int > &chunk_indices)=0
 Return the indices of all chunks on a specified node.
virtual void reset (void)=0
 Clear all cached parameters other than n, k and w.

Static Public Member Functions

static Codinguse_coding (int type, int k, int n, int w)
 Return an instance of a coding scheme, based on user's choice.

Protected Member Functions

virtual void read_metadata (std::string &path, size_t &chunksize)
 Read metadata from disk.
virtual void write_metadata (std::string &path, size_t chunksize)
 Write metadata to disk.
virtual void read_chunks (std::string &path, size_t chunksize, std::vector< int > &chunk_indices, char *chunks)
 Read chunks from disk to a single char buffer.
virtual void write_chunks (std::string &path, size_t chunksize, std::vector< int > &chunk_indices, char *chunks)
 Write chunks to disk from a single char buffer.

Detailed Description

Abstract base class for coding modules.


Member Function Documentation

virtual int Coding::chunks_on_node ( int  node,
std::vector< int > &  chunk_indices 
) [pure virtual]

Return the indices of all chunks on a specified node.

Parameters:
[in]nodenode number
[out]chunk_indicesvector of chunk indices on node
Returns:
0 on success, -1 on failure
virtual int Coding::chunks_per_node ( void  ) [pure virtual]

Return the number of chunks per node.

Returns:
the number of chunks per node on success, -1 on failure
virtual int Coding::decode_file ( std::string &  dst,
std::string &  srcdir,
std::string &  filename,
std::vector< int > &  chunk_indices 
) [pure virtual]

Reconstruct a file from chunks under srcdir into dst.

Parameters:
[in]dstpathname of reconstructed file
[in]srcdirdirectory where retrieved chunks used for decoding are stored
[in]filenamefilename of file to reconstruct
[in]chunk_indicesIndices of chunks retrieved for use in decoding
Returns:
0 on success, -1 on failure
virtual int Coding::encode_file ( std::string &  dstdir,
std::string &  srcdir,
std::string &  filename 
) [pure virtual]

Encode a file at srcdir/filename into chunks stored under dstdir.

Parameters:
[in]dstdirdestination directory where encoded chunks are stored
[in]srcdirsource directory of source file to be encoded
[in]filenamefilename of source file to be encoded
Returns:
0 on success, -1 on failure
virtual int Coding::getk ( void  ) [pure virtual]

Return the number of nodes required to reconstruct data.

Returns:
the total number of nodes on success, -1 on failure
virtual int Coding::getn ( void  ) [pure virtual]

Return the total number of nodes.

Returns:
the total number of nodes on success, -1 on failure
virtual int Coding::nodeid ( int  index) [pure virtual]

Return ID of the node where a specified chunk resides.

Parameters:
[in]indexchunk index
Returns:
the corresponding node id on success, -1 on failure
void Coding::read_chunks ( std::string &  path,
size_t  chunksize,
std::vector< int > &  chunk_indices,
char *  chunks 
) [protected, virtual]

Read chunks from disk to a single char buffer.

Parameters:
[in]pathpath to chunks without the ".chunk_" suffix
[in]chunksizesize of a chunk
[in]chunk_indiceslist of chunk indices to read
[out]chunkssingle char buffer holding chunks, following order in chunk_indices
void Coding::read_metadata ( std::string &  path,
size_t &  chunksize 
) [protected, virtual]

Read metadata from disk.

Parameters:
[in]pathpath to metadata without the ".meta" suffix
[out]chunksizechunk size read from the metadata
virtual int Coding::repair_file ( std::string &  dstdir,
std::string &  srcdir,
std::string &  filename 
) [pure virtual]

Generate new chunks to replace failed chunks.

Parameters:
[in]dstdirdestination directory to store the new chunks
[in]srcdirdirectory where retrieved chunks are at
[in]filenamefilename of file to repair
Returns:
0 on success, -1 on failure
virtual int Coding::repair_file_preprocess ( std::string &  srcdir,
std::string &  filename,
std::vector< int > &  erasures,
std::vector< int > &  chunks_to_retrieve 
) [pure virtual]

Setup repair and inform the user which chunks to retrieve for use in repair.

Parameters:
[in]srcdirdirectory where retrieved metadata is at
[in]filenamefilename of file to repair
[in]erasureslist of failed nodes
[out]chunks_to_retrieveIndices of chunks to be retrieved for use in repair
Returns:
0 on success, -1 on failure
virtual void Coding::reset ( void  ) [pure virtual]

Clear all cached parameters other than n, k and w.

Coding * Coding::use_coding ( int  type,
int  k,
int  n,
int  w 
) [static]

Return an instance of a coding scheme, based on user's choice.

Parameters:
[in]typechoice of coding scheme (0, 1 or 2)
[in]knumber of nodes required to reconstruct data
[in]ntotal number of nodes
[in]wfield width, w=8 if we use GF(2^8)
Returns:
an instance of an appropriate subclass of Coding
void Coding::write_chunks ( std::string &  path,
size_t  chunksize,
std::vector< int > &  chunk_indices,
char *  chunks 
) [protected, virtual]

Write chunks to disk from a single char buffer.

Parameters:
[in]pathpath to chunks without the ".chunk_" suffix
[in]chunksizesize of a chunk
[in]chunk_indiceslist of chunk indices to read
[in]chunkssingle char buffer holding chunks, following order in chunk_indices
void Coding::write_metadata ( std::string &  path,
size_t  chunksize 
) [protected, virtual]

Write metadata to disk.

Parameters:
[in]pathpath to metadata without the ".meta" suffix
[in]chunksizechunk size to write to the metadata

The documentation for this class was generated from the following files:
 All Data Structures Files Functions Variables Enumerations Enumerator Defines