Skip to content

Commit 6026a71

Browse files
committed
add storage option check
1 parent be857b8 commit 6026a71

File tree

9 files changed

+94
-10
lines changed

9 files changed

+94
-10
lines changed

cpp/ppc-framework/protocol/Protocol.h

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#define WIN32_LEAN_AND_MEAN
2424
#include <windows.h>
2525
#endif
26-
26+
#include "ppc-framework/Common.h"
2727
#include <bcos-utilities/Log.h>
2828
#include <map>
2929
#include <memory>
@@ -402,6 +402,35 @@ struct SQLConnectionOption
402402
std::string user;
403403
std::string password;
404404
std::string database;
405+
void check() const
406+
{
407+
if (host.size() == 0)
408+
{
409+
BOOST_THROW_EXCEPTION(WeDPRException() << bcos::errinfo_comment(
410+
"Invalid SQL option: Must set the host!"));
411+
}
412+
if (user.size() == 0)
413+
{
414+
BOOST_THROW_EXCEPTION(WeDPRException() << bcos::errinfo_comment(
415+
"Invalid SQL option: Must set the user!"));
416+
}
417+
if (password.size() == 0)
418+
{
419+
BOOST_THROW_EXCEPTION(WeDPRException() << bcos::errinfo_comment(
420+
"Invalid SQL option: Must set the password!"));
421+
}
422+
if (database.size() == 0)
423+
{
424+
BOOST_THROW_EXCEPTION(WeDPRException() << bcos::errinfo_comment(
425+
"Invalid SQL option: Must set the database!"));
426+
}
427+
if (port == 0 || port > 65535)
428+
{
429+
BOOST_THROW_EXCEPTION(WeDPRException() << bcos::errinfo_comment(
430+
"Invalid SQL Option, Must set valid port!"));
431+
}
432+
}
433+
405434
inline std::string desc() const
406435
{
407436
std::stringstream oss;
@@ -423,6 +452,25 @@ struct FileStorageConnectionOption
423452
bool replaceDataNodeOnFailure = false;
424453
// the default connection-timeout for the hdfs is 1000ms
425454
uint16_t connectionTimeout = 1000;
455+
456+
void check() const
457+
{
458+
if (nameNode.size() == 0)
459+
{
460+
BOOST_THROW_EXCEPTION(WeDPRException() << bcos::errinfo_comment(
461+
"Invalid HDFS Option, Must set the nameNode!"));
462+
}
463+
if (userName.size() == 0)
464+
{
465+
BOOST_THROW_EXCEPTION(WeDPRException() << bcos::errinfo_comment(
466+
"Invalid HDFS Option, Must set the userName!"));
467+
}
468+
if (nameNodePort == 0 || nameNodePort > 65535)
469+
{
470+
BOOST_THROW_EXCEPTION(WeDPRException() << bcos::errinfo_comment(
471+
"Invalid HDFS Option, Must set valid namenodeport!"));
472+
}
473+
}
426474
inline std::string desc() const
427475
{
428476
std::stringstream oss;

cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiCache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,5 +266,5 @@ void CalculatorCache::setIntersectionCipher(std::map<uint32_t, bcos::bytes>&& _c
266266
m_intersectionCipher = std::move(_cipherData);
267267
m_receiveIntersection = true;
268268
ECDH_MULTI_LOG(INFO) << LOG_DESC("setIntersectionCipher")
269-
<< LOG_KV("dataSize", _cipherData.size()) << printCacheState();
269+
<< LOG_KV("dataSize", m_intersectionCipher.size()) << printCacheState();
270270
}

cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/core/EcdhMultiPSICalculator.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ void EcdhMultiPSICalculator::loadAndEncrypt(std::string _taskID, bcos::bytes _ra
167167
seq);
168168
dataOffset += dataBatch->size();
169169
}
170-
dataBatch->release();
171170
} while (!m_taskState->sqlReader());
172171
}
173172
catch (std::exception& e)

cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/core/EcdhMultiPSIMaster.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ void EcdhMultiPSIMaster::encAndSendIntersectionData()
9898
for (auto& calcultor : m_calculatorParties)
9999
{
100100
ECDH_MASTER_LOG(INFO) << LOG_DESC("send intersection cipher to calculator")
101+
<< LOG_KV("taskID", m_taskState->task()->id())
102+
<< LOG_KV("intersectionSize", encryptedData.size())
101103
<< LOG_KV("target", calcultor.first);
102104
m_config->generateAndSendPPCMessage(calcultor.first, m_taskID, message,
103105
[self = weak_from_this()](bcos::Error::Ptr&& _error) {

cpp/wedpr-helper/ppc-tools/src/config/PPCConfig.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ void PPCConfig::loadHDFSConfig(boost::property_tree::ptree const& _pt)
559559
// the name node port
560560
option->nameNodePort = _pt.get<int>("hdfs_storage.name_node_port", 8020);
561561
// the user
562-
option->userName = _pt.get<std::string>("hdfs_storage.user", "root");
562+
option->userName = _pt.get<std::string>("hdfs_storage.user", "");
563563
// checkNonEmptyField("hdfs_storage.user", option->userName);
564564
// the token
565565
option->token = _pt.get<std::string>("hdfs_storage.token", "");

cpp/wedpr-storage/ppc-io/src/DataResourceLoaderImpl.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,40 @@ DataResourceLoaderImpl::DataResourceLoaderImpl(
4646
m_sqlStorageFactory(_sqlStorageFactory),
4747
m_fileStorageFactory(_fileStorageFactory),
4848
m_remoteStorageFactory(_remoteStorageFactory)
49+
{}
50+
51+
void DataResourceLoaderImpl::lazyLoadHdfsStorage()
4952
{
50-
if (m_fileStorageConnectionOpt)
53+
if (!m_fileStorageConnectionOpt)
5154
{
52-
m_hdfsStorage = m_fileStorageFactory->createFileStorage(
53-
DataResourceType::HDFS, m_fileStorageConnectionOpt);
55+
return;
5456
}
55-
if (m_sqlConnectionOpt)
57+
bcos::Guard l(x_hdfsStorage);
58+
if (m_hdfsStorage)
5659
{
57-
m_sqlStorage =
58-
m_sqlStorageFactory->createSQLStorage(DataResourceType::MySQL, m_sqlConnectionOpt);
60+
return;
5961
}
62+
m_hdfsStorage =
63+
m_fileStorageFactory->createFileStorage(DataResourceType::HDFS, m_fileStorageConnectionOpt);
64+
IO_LOG(INFO) << LOG_DESC("lazyLoadHdfsStorage") << m_fileStorageConnectionOpt->desc();
65+
return;
6066
}
6167

68+
void DataResourceLoaderImpl::lazyLoadSqlStorage()
69+
{
70+
if (!m_sqlConnectionOpt)
71+
{
72+
return;
73+
}
74+
bcos::Guard l(x_sqlStorage);
75+
if (m_sqlStorage)
76+
{
77+
return;
78+
}
79+
m_sqlStorage =
80+
m_sqlStorageFactory->createSQLStorage(DataResourceType::MySQL, m_sqlConnectionOpt);
81+
IO_LOG(INFO) << LOG_DESC("lazyLoadSqlStorage") << m_sqlConnectionOpt->desc();
82+
}
6283

6384
LineReader::Ptr DataResourceLoaderImpl::loadReader(DataResourceDesc::ConstPtr _desc,
6485
DataSchema _schema, bool _parseByColumn, FileStorage::Ptr const& _fileStorage)
@@ -104,6 +125,7 @@ LineReader::Ptr DataResourceLoaderImpl::loadSQLResource(
104125
}
105126
else if (m_sqlConnectionOpt)
106127
{
128+
lazyLoadSqlStorage();
107129
storage = m_sqlStorage;
108130
}
109131
else
@@ -133,6 +155,7 @@ LineReader::Ptr DataResourceLoaderImpl::loadHDFSResource(
133155
}
134156
else if (m_fileStorageConnectionOpt)
135157
{
158+
lazyLoadHdfsStorage();
136159
storage = m_hdfsStorage;
137160
}
138161
else
@@ -170,6 +193,7 @@ void DataResourceLoaderImpl::deleteResource(
170193
}
171194
else if (m_fileStorageConnectionOpt)
172195
{
196+
lazyLoadHdfsStorage();
173197
storage = m_hdfsStorage;
174198
}
175199
else
@@ -219,6 +243,7 @@ void DataResourceLoaderImpl::renameResource(ppc::protocol::DataResourceDesc::Con
219243
}
220244
else if (m_fileStorageConnectionOpt)
221245
{
246+
lazyLoadHdfsStorage();
222247
storage = m_hdfsStorage;
223248
}
224249
else
@@ -277,6 +302,7 @@ void DataResourceLoaderImpl::checkResourceExists(
277302
}
278303
else if (m_fileStorageConnectionOpt)
279304
{
305+
lazyLoadHdfsStorage();
280306
storage = m_hdfsStorage;
281307
}
282308
else
@@ -330,6 +356,7 @@ LineWriter::Ptr DataResourceLoaderImpl::loadWriter(
330356
}
331357
else if (m_fileStorageConnectionOpt)
332358
{
359+
lazyLoadHdfsStorage();
333360
storage = m_hdfsStorage;
334361
}
335362
else

cpp/wedpr-storage/ppc-io/src/DataResourceLoaderImpl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,19 @@ class DataResourceLoaderImpl : public DataResourceLoader
6363
virtual LineReader::Ptr loadHDFSResource(ppc::protocol::DataResourceDesc::ConstPtr _desc,
6464
ppc::storage::FileStorage::Ptr const& _fileStorage);
6565

66+
void lazyLoadHdfsStorage();
67+
void lazyLoadSqlStorage();
68+
6669
private:
6770
// the sql storage
6871
ppc::protocol::SQLConnectionOption::Ptr m_sqlConnectionOpt;
6972
ppc::storage::SQLStorage::Ptr m_sqlStorage;
73+
bcos::Mutex x_sqlStorage;
74+
7075
// the hdfs storage
7176
ppc::protocol::FileStorageConnectionOption::Ptr m_fileStorageConnectionOpt;
7277
ppc::storage::FileStorage::Ptr m_hdfsStorage;
78+
bcos::Mutex x_hdfsStorage;
7379

7480
ppc::protocol::RemoteStorageConnectionOption::Ptr m_remoteStorageConnectionOpt;
7581

cpp/wedpr-storage/ppc-storage/src/FileStorageFactoryImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class FileStorageFactoryImpl : public FileStorageFactory
3636
{
3737
case ppc::protocol::DataResourceType::HDFS:
3838
{
39+
_option->check();
3940
return std::make_shared<HDFSStorage>(_option);
4041
}
4142
default:

cpp/wedpr-storage/ppc-storage/src/SQLStorageFactoryImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class SQLStorageFactoryImpl : public SQLStorageFactory
3939
{
4040
case ppc::protocol::DataResourceType::MySQL:
4141
{
42+
_option->check();
4243
return std::make_shared<MySQLStorage>(_option);
4344
}
4445
default:

0 commit comments

Comments
 (0)