Skip to content

Commit 9503f74

Browse files
authored
[PSL-1223] pasteld: implement debug log rotation (#257)
* [PSL-1223] pasteld: implement debug log rotation pasteld v2.2.5 - moved all log functionality to separate class CLogManager - implemented log file rotation - debog.log file with size > 10Mb is moved to the /old_logs folder with timestamp. New log file is created. - moved global log variables to the new CLogManager class - added missing locking for some log functions - created new thread class CLogRotationManager responsible for checking log file size and moving it to old_logs folder - CLogRotationManager thread (psl-logrt) is created on startup. It checks every 10 mins whether log needs rotation. Also it uses CStoppableServiceThread that can stop by cond var signal. other fixes: - fixed wait for PastelMiner threads
1 parent b66393d commit 9503f74

30 files changed

+599
-415
lines changed

build-aux/vs2022/libbitcoin_util/libbitcoin_util.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
<ClCompile Include="..\..\..\src\utils\bech32.cpp" />
110110
<ClCompile Include="..\..\..\src\utils\datacompressor.cpp" />
111111
<ClCompile Include="..\..\..\src\utils\hash.cpp" />
112+
<ClCompile Include="..\..\..\src\utils\logmanager.cpp" />
112113
<ClCompile Include="..\..\..\src\utils\ping_util.cpp" />
113114
<ClCompile Include="..\..\..\src\utils\random.cpp" />
114115
<ClCompile Include="..\..\..\src\utils\scheduler.cpp" />
@@ -142,9 +143,11 @@
142143
<ClInclude Include="..\..\..\src\utils\base58.h" />
143144
<ClInclude Include="..\..\..\src\utils\bech32.h" />
144145
<ClInclude Include="..\..\..\src\utils\datacompressor.h" />
146+
<ClInclude Include="..\..\..\src\utils\detect_cpp_standard.h" />
145147
<ClInclude Include="..\..\..\src\utils\enum_util.h" />
146148
<ClInclude Include="..\..\..\src\utils\fs.h" />
147149
<ClInclude Include="..\..\..\src\utils\hash.h" />
150+
<ClInclude Include="..\..\..\src\utils\logmanager.h" />
148151
<ClInclude Include="..\..\..\src\utils\map_types.h" />
149152
<ClInclude Include="..\..\..\src\utils\numeric_range.h" />
150153
<ClInclude Include="..\..\..\src\utils\ping_util.h" />

build-aux/vs2022/libbitcoin_util/libbitcoin_util.vcxproj.filters

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@
100100
<ClCompile Include="..\..\..\src\utils\hash.cpp">
101101
<Filter>Source Files\utils</Filter>
102102
</ClCompile>
103+
<ClCompile Include="..\..\..\src\utils\logmanager.cpp">
104+
<Filter>Source Files\utils</Filter>
105+
</ClCompile>
103106
</ItemGroup>
104107
<ItemGroup>
105108
<ClInclude Include="..\..\..\src\compat\byteswap.h">
@@ -246,5 +249,11 @@
246249
<ClInclude Include="..\..\..\src\utils\hash.h">
247250
<Filter>Source Files\utils</Filter>
248251
</ClInclude>
252+
<ClInclude Include="..\..\..\src\utils\logmanager.h">
253+
<Filter>Source Files\utils</Filter>
254+
</ClInclude>
255+
<ClInclude Include="..\..\..\src\utils\detect_cpp_standard.h">
256+
<Filter>Source Files\utils</Filter>
257+
</ClInclude>
249258
</ItemGroup>
250259
</Project>

configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
22
AC_PREREQ([2.60])
33
define(_CLIENT_VERSION_MAJOR, 2)
44
define(_CLIENT_VERSION_MINOR, 2)
5-
define(_CLIENT_VERSION_REVISION, 4)
6-
define(_CLIENT_VERSION_BUILD, 3)
5+
define(_CLIENT_VERSION_REVISION, 5)
6+
define(_CLIENT_VERSION_BUILD, 0)
77
define(_ZC_BUILD_VAL,
88
m4_if(m4_eval(_CLIENT_VERSION_BUILD < 25), 1, m4_incr(_CLIENT_VERSION_BUILD),
99
m4_eval(_CLIENT_VERSION_BUILD < 50), 1,

qa/rpc-tests/mn_bugs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def test_40104615 (self):
273273
assert_equal(res1['result'], 'successful')
274274
ticket2_id = res1['ticketId']
275275

276-
print ("Minig after 2nd ticket...")
276+
print ("Mining after 2nd ticket...")
277277
time.sleep(3)
278278
self.slow_mine(2, 10, 2, 0.5)
279279

qa/rpc-tests/mn_common.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def setup_masternodes_network(self, debug_flags: str = ""):
379379
mn.mnid = params["mnid"]
380380
mn.lrKey = params["legRoastKey"]
381381
mn.privKey = params["privKey"]
382-
print(f"mn{index} id: {mn.mnid}")
382+
print(f"mn{mn.index} id: {mn.mnid}")
383383
mn.create_masternode_conf(self.options.tmpdir, self.hot_node_num)
384384
else:
385385
mn.privKey = self.nodes[self.hot_node_num].masternode("genkey")
@@ -390,7 +390,12 @@ def setup_masternodes_network(self, debug_flags: str = ""):
390390
# starting all master nodes
391391
for mn in self.mn_nodes:
392392
print(f"starting masternode {mn.alias}")
393-
self.nodes[mn.index] = start_node(mn.index, self.options.tmpdir, [f"-debug={debug_flags}", "-masternode", "-txindex=1", "-reindex", f"-masternodeprivkey={mn.privKey}"])
393+
self.nodes[mn.index] = start_node(mn.index, self.options.tmpdir,
394+
[f"-debug={debug_flags}",
395+
"-masternode",
396+
"-txindex=1",
397+
"-reindex",
398+
f"-masternodeprivkey={mn.privKey}"])
394399

395400
# connect nodes (non-mn nodes already interconnected)
396401
for pair in itertools.combinations(range(self.total_number_of_nodes), 2):

qa/rpc-tests/mn_messaging.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
# Copyright (c) 2018-2023 The Pastel Core developers
2+
# Copyright (c) 2018-2024 The Pastel Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or https://www.opensource.org/licenses/mit-license.php.
55
import time
@@ -14,10 +14,11 @@ class MasterNodeMessagingTest(MasterNodeCommon):
1414

1515
def __init__(self):
1616
super().__init__()
17-
17+
1818
self.number_of_master_nodes = 4
1919
self.number_of_simple_nodes = 3
2020
self.number_of_cold_nodes = self.number_of_master_nodes
21+
self.num_nodes = self.number_of_master_nodes + self.number_of_simple_nodes
2122

2223
self.non_active_mn = self.number_of_master_nodes - 1
2324

@@ -27,17 +28,13 @@ def __init__(self):
2728

2829
self.mining_node_num = self.number_of_master_nodes # same as non_mn1
2930
self.hot_node_num = self.number_of_master_nodes+1 # same as non_mn2
31+
self.setup_clean_chain = True
32+
self.is_network_split = False
3033

3134

32-
def setup_chain(self):
33-
print("Initializing test directory "+self.options.tmpdir)
34-
initialize_chain_clean(self.options.tmpdir, self.total_number_of_nodes)
35-
3635
def setup_network(self, split=False):
37-
self.nodes = []
38-
self.is_network_split = False
3936
self.setup_masternodes_network()
40-
37+
4138

4239
def run_test(self):
4340
mns = self.nodes[0].masternodelist("pubkey")

qa/rpc-tests/test_framework/authproxy.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,23 @@
3535

3636
import base64
3737
import decimal
38-
from http.client import HTTPConnection, HTTPSConnection, BadStatusLine
38+
from http.client import (
39+
HTTPConnection,
40+
HTTPSConnection,
41+
BadStatusLine,
42+
RemoteDisconnected,
43+
)
3944
from urllib.parse import urlparse
4045
import logging
4146
import simplejson as json
47+
import time
4248

4349
USER_AGENT = "AuthServiceProxy/0.1"
4450

45-
HTTP_TIMEOUT_IN_SECS = 900
51+
HTTP_TIMEOUT_IN_SECS = 1000
52+
HTTP_MAX_RETRIES = 5
53+
HTTP_RETRY_DELAY_SECS = 2
54+
4655

4756
log = logging.getLogger("PastelRPC")
4857

@@ -131,22 +140,21 @@ def _request(self, method, path, postdata):
131140
'Authorization': self.__auth_header,
132141
'Connection': 'keep-alive',
133142
'Content-type': 'application/json'}
134-
try:
135-
self.__conn.request(method, path, postdata, headers)
136-
return self._get_response()
137-
except Exception as e:
138-
# If connection was closed, try again.
139-
# Python 3.5+ raises BrokenPipeError instead of BadStatusLine when the connection was reset.
140-
# ConnectionResetError happens on FreeBSD with Python 3.4.
141-
# This can be simplified now that we depend on Python 3 (previously, we could not
142-
# refer to BrokenPipeError or ConnectionResetError which did not exist on Python 2)
143-
if ((isinstance(e, BadStatusLine) and (e.line == "''" or e.line == "No status line received - the server has closed the connection"))
144-
or e.__class__.__name__ in ('BrokenPipeError', 'ConnectionResetError')):
145-
self.__conn.close()
143+
for attempt in range(HTTP_MAX_RETRIES):
144+
try:
146145
self.__conn.request(method, path, postdata, headers)
147146
return self._get_response()
148-
else:
149-
raise
147+
except (RemoteDisconnected, BadStatusLine, ConnectionRefusedError, BrokenPipeError, ConnectionResetError) as e:
148+
if attempt < HTTP_MAX_RETRIES - 1:
149+
log.warning(f"Attempt {attempt + 1} failed: {e}. Retrying in {HTTP_RETRY_DELAY_SECS} seconds...")
150+
self.__conn.close()
151+
time.sleep(HTTP_RETRY_DELAY_SECS)
152+
else:
153+
log.error(f"All {HTTP_MAX_RETRIES} attempts failed. Raising exception.")
154+
raise
155+
except Exception as e:
156+
log.error(f"Unhandled exception: {e}. Raising exception.")
157+
raise
150158

151159

152160
def __call__(self, *args):

qa/rpc-tests/test_framework/test_framework.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ class BitcoinTestFramework(object):
5555
_1000patoshi = Decimal('0.01')
5656
_10000patoshi = Decimal('0.1')
5757
_1ani = Decimal('1.0')
58-
58+
59+
5960
def __init__(self):
6061
self.num_nodes = 4
6162
self.setup_clean_chain = False
62-
self.nodes = None
63+
self.nodes = []
6364
self.is_network_split = False
6465

6566
def run_test(self):

qa/rpc-tests/timestampindex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def setup_network(self):
3030
# -insightexplorer causes spentindex to be enabled (fSpentIndex = true)
3131

3232
self.nodes = start_nodes(
33-
3, self.options.tmpdir,
33+
self.num_nodes, self.options.tmpdir,
3434
[[
3535
'-debug=rpc',
3636
'-txindex',

src/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ UTILS_CPP = \
252252
utils/bech32.cpp \
253253
utils/datacompressor.cpp \
254254
utils/hash.cpp \
255+
utils/logmanager.cpp \
255256
utils/ping_util.cpp \
256257
utils/random.cpp \
257258
utils/scheduler.cpp \
@@ -268,9 +269,11 @@ UTILS_H = \
268269
utils/base58.h \
269270
utils/bech32.h \
270271
utils/datacompressor.h \
272+
utils/detect_cpp_standard.h \
271273
utils/enum_util.h \
272274
utils/fs.h \
273275
utils/hash.h \
276+
utils/logmanager.h \
274277
utils/map_types.h \
275278
utils/numeric_range.h \
276279
utils/ping_util.h \

0 commit comments

Comments
 (0)