-
Notifications
You must be signed in to change notification settings - Fork 0
/
DuplicationManager.cpp
55 lines (48 loc) · 1.65 KB
/
DuplicationManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*************************************************************************
> File Name: DuplicationManager.cpp
> Author: Weidong, ZHANG
> Mail: [email protected]
> Created Time: Tue 09 Dec 2014 07:10:25 AM PST
************************************************************************/
#include "DuplicationManager.h"
namespace pdfs {
DuplicationManager::DuplicationManager()
{ }
DuplicationManager::~DuplicationManager()
{ }
ssize_t DuplicationManager::addMetadata(NetworkInterface &netinterface,
Metadata& metadata, std::string dest)
{
if(-1 == netinterface.pushMetadata(metadata, dest)) return -1;
return 0;
}
ssize_t DuplicationManager::backupMetadata(NetworkInterface &netinterface,
Metadata &metadata)
{
std::vector<std::string> nodes = Cluster::getMetaNode(metadata.filename);
for(size_t i = 0; i < nodes.size(); i++)
if (!Cluster::isLocalIP(nodes[i]))
addMetadata(netinterface, metadata, nodes[i]);
return 0;
}
ssize_t DuplicationManager::addFile(NetworkInterface &netinterface,
Metadata &metadata, std::string dest)
{
if (-1 == netinterface.pushFile(metadata, dest))
return -1;
return 0;
}
ssize_t DuplicationManager::backupFile(NetworkInterface &netinterface,
Metadata &metadata)
{
for (int i = 0; i < sizeof(metadata.destnode) / IPSTRLEN; i++)
{
std::string destnode(metadata.destnode + i * IPSTRLEN,
metadata.destnode + (i + 1) * IPSTRLEN);
StringUtil::trim(destnode);
if (!destnode.empty() && !Cluster::isLocalIP(destnode))
addFile(netinterface, metadata, destnode);
}
return 0;
}
} // end of namespace pdfs