File: chunk_replicator.h

package info (click to toggle)
lizardfs 3.12.0+dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 8,064 kB
  • sloc: cpp: 91,899; sh: 9,341; python: 3,878; ansic: 3,109; pascal: 128; makefile: 57
file content (75 lines) | stat: -rw-r--r-- 2,133 bytes parent folder | download | duplicates (2)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
   Copyright 2013-2017 Skytechnology sp. z o.o.

   This file is part of LizardFS.

   LizardFS is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, version 3.

   LizardFS is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with LizardFS. If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include "common/platform.h"

#include <cstdint>
#include <memory>
#include <mutex>

#include "chunkserver/chunk_file_creator.h"
#include "chunkserver/slice_recovery_planner.h"
#include "common/chunk_connector.h"
#include "common/chunk_type_with_address.h"
#include "common/chunkserver_stats.h"
#include "common/exception.h"

class ChunkReplicator {
public:
	static constexpr unsigned kDefaultTotalTimeout_ms = 60 * 1000;
	static constexpr unsigned kDefaultWaveTimeout_ms = 500;
	static constexpr unsigned kDefaultConnectionTimeout_ms = 1000;

	ChunkReplicator(ChunkConnector& connector);
	void replicate(ChunkFileCreator& fileCreator, const std::vector<ChunkTypeWithAddress>& sources);
	uint32_t getStats();

	void setTotalTimeout(unsigned timeout_ms) {
		total_timeout_ms_ = timeout_ms;
	}

	void setWaveTimeout(unsigned timeout_ms) {
		wave_timeout_ms_ = timeout_ms;
	}

	void setConnectionTimeout(unsigned timeout_ms) {
		connection_timeout_ms_ = timeout_ms;
	}

private:
	ChunkserverStats chunkserverStats_;
	ChunkConnector& connector_;
	uint32_t stats_;
	std::mutex mutex_;

	uint32_t getChunkBlocks(uint64_t chunkId, uint32_t chunkVersion,
			ChunkTypeWithAddress type_with_address);

	uint32_t getChunkBlocks(uint64_t chunkId, uint32_t chunkVersion,
			const std::vector<ChunkTypeWithAddress>& sources);

	void incStats();

	unsigned total_timeout_ms_;
	unsigned wave_timeout_ms_;
	unsigned connection_timeout_ms_;
};

extern ChunkReplicator gReplicator;