-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathAdminRegion.cpp
More file actions
148 lines (126 loc) · 4.55 KB
/
AdminRegion.cpp
File metadata and controls
148 lines (126 loc) · 4.55 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "AdminRegion.hpp"
#include <boost/thread/lock_types.hpp>
#include <geode/SystemProperties.hpp>
#include "CacheImpl.hpp"
#include "TcrConnectionManager.hpp"
#include "ThinClientCacheDistributionManager.hpp"
#include "ThinClientPoolDM.hpp"
#include "ThinClientRegion.hpp"
#include "util/exception.hpp"
namespace apache {
namespace geode {
namespace client {
std::shared_ptr<AdminRegion> AdminRegion::create(CacheImpl* cache,
ThinClientBaseDM* distMan) {
auto adminRegion = std::make_shared<AdminRegion>();
auto& props = cache->getDistributedSystem().getSystemProperties();
if (props.statisticsEnabled()) {
// no need to create a region .. just create a cacheDistribution Manager
adminRegion->m_connectionMgr = &(cache->tcrConnectionManager());
if (!distMan) {
adminRegion->m_distMngr =
new ThinClientCacheDistributionManager(*adminRegion->m_connectionMgr);
cache->getStatisticsManager().RegisterAdminRegion(adminRegion);
} else {
adminRegion->m_distMngr = distMan;
}
}
return adminRegion;
}
void AdminRegion::init() {
// Init distribution manager if it is not a pool
if (m_distMngr && !dynamic_cast<ThinClientPoolDM*>(m_distMngr)) {
m_distMngr->init();
}
}
TcrConnectionManager* AdminRegion::getConnectionManager() {
return m_connectionMgr;
}
void AdminRegion::put(const std::shared_ptr<CacheableKey>& keyPtr,
const std::shared_ptr<Cacheable>& valuePtr) {
GfErrType err = putNoThrow(keyPtr, valuePtr);
throwExceptionIfError("AdminRegion::put", err);
}
GfErrType AdminRegion::putNoThrow(const std::shared_ptr<CacheableKey>& keyPtr,
const std::shared_ptr<Cacheable>& valuePtr) {
// put obj to region
GfErrType err = GF_NOERR;
TcrMessagePut request(
new DataOutput(m_connectionMgr->getCacheImpl()->createDataOutput()),
nullptr, keyPtr, valuePtr, nullptr, false, m_distMngr, true, false,
m_fullPath.c_str());
request.setMetaRegion(true);
TcrMessageReply reply(true, m_distMngr);
reply.setMetaRegion(true);
err = m_distMngr->sendSyncRequest(request, reply, true, true);
if (err != GF_NOERR) {
return err;
}
// put the object into local region
switch (reply.getMessageType()) {
case TcrMessage::REPLY: {
LOGDEBUG(
"AdminRegion::put: entry is written into remote server "
"at region %s",
m_fullPath.c_str());
break;
}
case TcrMessage::EXCEPTION: {
const auto& exceptionMsg = reply.getException();
err = ThinClientRegion::handleServerException("AdminRegion::put",
exceptionMsg);
break;
}
case TcrMessage::PUT_DATA_ERROR: {
LOGERROR("A write error occurred on the endpoint %s",
m_distMngr->getActiveEndpoint()->name().c_str());
err = GF_CACHESERVER_EXCEPTION;
break;
}
default: {
LOGERROR("Unknown message type in put reply %d", reply.getMessageType());
err = GF_MSG;
}
}
return err;
}
void AdminRegion::close() {
boost::unique_lock<decltype(m_rwMutex)> guard{m_rwMutex};
if (m_destroyPending) {
return;
}
m_destroyPending = true;
// Close distribution manager if it is not a pool
if (m_distMngr != nullptr &&
dynamic_cast<ThinClientPoolDM*>(m_distMngr) == nullptr) {
m_distMngr->destroy();
_GEODE_SAFE_DELETE(m_distMngr);
}
}
AdminRegion::~AdminRegion() {
// destructor should be single threaded in any case, so no need of guard
if (m_distMngr != nullptr) {
close();
}
}
const bool& AdminRegion::isDestroyed() { return m_destroyPending; }
boost::shared_mutex& AdminRegion::getMutex() { return m_rwMutex; }
} // namespace client
} // namespace geode
} // namespace apache