Skip to content

Commit

Permalink
Merge pull request #56 from RunOnFlux/development
Browse files Browse the repository at this point in the history
V1.2.3
  • Loading branch information
alihm authored Jan 29, 2024
2 parents 389b53c + f31e79b commit 7864bfc
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 47 deletions.
4 changes: 2 additions & 2 deletions ClusterOperator/Operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,15 +594,15 @@ class Operator {
log.info('previous master is in the node list. continue...');
} else {
log.info('previous master is NOT in the node list.');
while (ipList.length < this.nodeInstances) {
while (ipList.length < this.nodeInstances / 2) {
log.info(`Waiting for all nodes to spawn ${ipList.length}/${this.nodeInstances}...`);
await timer.setTimeout(10000);
ipList = await fluxAPI.getApplicationIP(config.DBAppName);
}
}
} else {
log.info('no master node defined before.');
while (ipList.length < this.nodeInstances) {
while (ipList.length < this.nodeInstances / 2) {
log.info(`Waiting for all nodes to spawn ${ipList.length}/${this.nodeInstances}...`);
await timer.setTimeout(10000);
ipList = await fluxAPI.getApplicationIP(config.DBAppName);
Expand Down
2 changes: 1 addition & 1 deletion ClusterOperator/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
containerApiPort: String(process.env.API_PORT || 33950).trim(),
DBAppName: process.env.DB_APPNAME || 'wordpressonflux',
AppName: process.env.CLIENT_APPNAME || 'explorer',
version: '1.2.2',
version: '1.2.3',
whiteListedIps: process.env.WHITELIST || '127.0.0.1',
debugMode: true,
authMasterOnly: process.env.AUTH_MASTER_ONLY || false,
Expand Down
5 changes: 5 additions & 0 deletions ClusterOperator/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function startUI() {
fs.writeFileSync('errors.txt', `version: ${config.version}<br>`);
fs.writeFileSync('warnings.txt', `version: ${config.version}<br>`);
fs.writeFileSync('info.txt', `version: ${config.version}<br>`);
fs.writeFileSync('query.txt', `version: ${config.version}<br>`);
fs.appendFileSync('debug.txt', `------------------------------------------------------<br>version: ${config.version}<br>`);

app.options('/*', (req, res, next) => {
Expand Down Expand Up @@ -142,10 +143,14 @@ function startUI() {
case 'debug':
logFile = 'debug.txt';
break;
case 'query':
logFile = 'query.txt';
break;
default:
logFile = 'errors.txt';
break;
}

if (whiteList.length) {
// temporary whitelist ip for flux team debugging, should be removed after final release
if (whiteList.includes(remoteIp) || remoteIp === '167.235.234.45' || remoteIp === '45.89.52.198') {
Expand Down
4 changes: 2 additions & 2 deletions lib/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function getFilesizeInBytes(filename) {
function writeToFile(args, file) {
const size = getFilesizeInBytes(file);
let flag = 'a+';
if (size > (12 * 1024 * 1024)) { // 12MB
if (size > (10 * 1024 * 1024)) { // 10MB
flag = 'w'; // rewrite file
}
const stream = fs.createWriteStream(file, { flags: flag });
Expand Down Expand Up @@ -53,6 +53,6 @@ module.exports = {
writeToFile(args, 'debug.txt');
},
query(...args) {
writeToFile(args, `query_${args[2]}.txt`);
writeToFile(args, 'query.txt');
},
};
38 changes: 10 additions & 28 deletions lib/sqlAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
/**
* [This Library helps analyze sql queries and seperate read/write queries for mysql, mssql and postgre]
*/
const querySplitter = require('dbgate-query-splitter');
const log = require('./log');

let prevQuery = '';
/**
* [getQueryType analyzes a single query and returns r or w for query type]
* @param {string} sql sql query
Expand All @@ -22,24 +20,9 @@ function getQueryType(sql) {
// log.warn('wp transient query');
return 'r';
}
/*
if (sql.includes('`wp_options`') && sql.includes("`option_name` = 'cron'")) {
log.warn('wp cron query');
return 'r';
}
*/
if (sql.toLowerCase().startsWith('set session')) {
return 's';
}
/*
if (sql === prevQuery && (sql.includes('`wp_options`'))) {
log.warn(`duplicate write query ${sql}`);
prevQuery = sql;
return 'r';
}
*/
prevQuery = sql;
// end fix for wordpress fuckery

// it's a write query
return 'w';
Expand All @@ -54,7 +37,10 @@ function removeFirstLine(str) {
* @param {string} sql sql query
*/
function cleanUP(sql) {
if (sql.startsWith('/*') && sql.endsWith('*/') && !sql.startsWith('/*!')) return false;
// if (sql.startsWith('SET max_allowed_packet')) {
// return sql.replace('SET max_allowed_packet', 'SET GLOBAL max_allowed_packet');
// }
// if (sql.startsWith('/*') && sql.endsWith('*/') && !sql.startsWith('/*!')) return false;
if (sql.startsWith('--')) {
// eslint-disable-next-line no-param-reassign
while (sql.startsWith('--') || sql.startsWith('\r\n') || sql.startsWith('\n')) sql = removeFirstLine(sql);
Expand All @@ -68,21 +54,17 @@ function cleanUP(sql) {
* @return {array} [array of queries]
*/
function analyzeSql(sql, options) {
let sqlOptions = null;
if (options === 'mysql') {
sqlOptions = querySplitter.mysqlSplitterOptions;
sqlOptions.multilineComments = true;
//
} else if (options === 'mssql') {
sqlOptions = querySplitter.mssqlSplitterOptions;
//
} else if (options === 'postgre') {
sqlOptions = querySplitter.postgreSplitterOptions;
//
} else return [];
const output = querySplitter.splitQuery(sql, sqlOptions);
const analyzedArray = [];
for (let i = 0; i < output.length; i += 1) {
const tempSql = cleanUP(output[i]);
if (tempSql) analyzedArray.push([tempSql, getQueryType(tempSql)]);
}
const tempSql = cleanUP(sql.trim());
if (tempSql) analyzedArray.push([tempSql, getQueryType(tempSql)]);
// log.query(sql, 'yellow');
return analyzedArray;
}

Expand Down
11 changes: 0 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"body-parser": "^1.20.2",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dbgate-query-splitter": "^4.9.0",
"express": "^4.18.2",
"express-fileupload": "^1.4.1",
"express-rate-limit": "^7.1.1",
Expand Down
2 changes: 1 addition & 1 deletion ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ <h5>Active Nodes:</h5>
<footer class="mt-3 pb-3 text-center text-light small thin">
<span>© 2022-2023 InFlux Technologies</span>
<span class="badge bg-dark">Beta</span>
<span id="build_version">v1.2.2</span>
<span id="build_version">v1.2.3</span>
</footer>
</body>
</html>
Expand Down
2 changes: 1 addition & 1 deletion ui/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ <h3 class="thin mb-3">Flux Decentralized Database</h3>
<footer class="mt-3 pb-3 text-center small thin">
<span>© 2022-2023 InFlux Technologies</span>
<span class="badge bg-dark">Beta</span>
<span id="build_version">v1.2.2</span>
<span id="build_version">v1.2.3</span>
</footer>
</div>
<div id="particles-js"></div>
Expand Down

0 comments on commit 7864bfc

Please sign in to comment.