feat: cluster implementation
This commit is contained in:
@@ -64,7 +64,8 @@ module.exports = {
|
||||
// Sync DB
|
||||
|
||||
self.onReady = self.inst.sync({
|
||||
force: false
|
||||
force: false,
|
||||
logging: false
|
||||
})
|
||||
|
||||
return self
|
||||
|
@@ -2,12 +2,10 @@
|
||||
|
||||
/* global wiki */
|
||||
|
||||
module.exports = (processName) => {
|
||||
let winston = require('winston')
|
||||
const cluster = require('cluster')
|
||||
|
||||
if (typeof processName === 'undefined') {
|
||||
processName = 'SERVER'
|
||||
}
|
||||
module.exports = () => {
|
||||
let winston = require('winston')
|
||||
|
||||
// Console
|
||||
|
||||
@@ -25,6 +23,7 @@ module.exports = (processName) => {
|
||||
})
|
||||
|
||||
logger.filters.push((level, msg) => {
|
||||
let processName = (cluster.isMaster) ? 'MASTER' : `WORKER-${cluster.worker.id}`
|
||||
return '[' + processName + '] ' + msg
|
||||
})
|
||||
|
||||
|
@@ -1,81 +0,0 @@
|
||||
const bunyan = require('bunyan')
|
||||
const level = require('levelup')
|
||||
const down = require('memdown')
|
||||
const SearchIndexAdder = require('search-index-adder')
|
||||
const SearchIndexSearcher = require('search-index-searcher')
|
||||
|
||||
module.exports = function (givenOptions, moduleReady) {
|
||||
const optionsLoaded = function (err, SearchIndex) {
|
||||
const siUtil = require('./siUtil.js')(SearchIndex.options)
|
||||
if (err) return moduleReady(err)
|
||||
SearchIndex.close = siUtil.close
|
||||
SearchIndex.countDocs = siUtil.countDocs
|
||||
getAdder(SearchIndex, adderLoaded)
|
||||
}
|
||||
|
||||
const adderLoaded = function (err, SearchIndex) {
|
||||
if (err) return moduleReady(err)
|
||||
getSearcher(SearchIndex, searcherLoaded)
|
||||
}
|
||||
|
||||
const searcherLoaded = function (err, SearchIndex) {
|
||||
if (err) return moduleReady(err)
|
||||
return moduleReady(err, SearchIndex)
|
||||
}
|
||||
|
||||
getOptions(givenOptions, optionsLoaded)
|
||||
}
|
||||
|
||||
const getAdder = function (SearchIndex, done) {
|
||||
SearchIndexAdder(SearchIndex.options, function (err, searchIndexAdder) {
|
||||
SearchIndex.add = searchIndexAdder.add
|
||||
SearchIndex.callbackyAdd = searchIndexAdder.concurrentAdd // deprecated
|
||||
SearchIndex.concurrentAdd = searchIndexAdder.concurrentAdd
|
||||
SearchIndex.createWriteStream = searchIndexAdder.createWriteStream
|
||||
SearchIndex.dbWriteStream = searchIndexAdder.dbWriteStream
|
||||
SearchIndex.defaultPipeline = searchIndexAdder.defaultPipeline
|
||||
SearchIndex.del = searchIndexAdder.deleter
|
||||
SearchIndex.deleteStream = searchIndexAdder.deleteStream
|
||||
SearchIndex.flush = searchIndexAdder.flush
|
||||
done(err, SearchIndex)
|
||||
})
|
||||
}
|
||||
|
||||
const getSearcher = function (SearchIndex, done) {
|
||||
SearchIndexSearcher(SearchIndex.options, function (err, searchIndexSearcher) {
|
||||
SearchIndex.availableFields = searchIndexSearcher.availableFields
|
||||
SearchIndex.buckets = searchIndexSearcher.bucketStream
|
||||
SearchIndex.categorize = searchIndexSearcher.categoryStream
|
||||
SearchIndex.dbReadStream = searchIndexSearcher.dbReadStream
|
||||
SearchIndex.get = searchIndexSearcher.get
|
||||
SearchIndex.match = searchIndexSearcher.match
|
||||
SearchIndex.scan = searchIndexSearcher.scan
|
||||
SearchIndex.search = searchIndexSearcher.search
|
||||
SearchIndex.totalHits = searchIndexSearcher.totalHits
|
||||
done(err, SearchIndex)
|
||||
})
|
||||
}
|
||||
|
||||
const getOptions = function (options, done) {
|
||||
var SearchIndex = {}
|
||||
SearchIndex.options = Object.assign({}, {
|
||||
indexPath: 'si',
|
||||
keySeparator: '○',
|
||||
logLevel: 'error'
|
||||
}, options)
|
||||
options.log = bunyan.createLogger({
|
||||
name: 'search-index',
|
||||
level: options.logLevel
|
||||
})
|
||||
if (!options.indexes) {
|
||||
level(SearchIndex.options.indexPath || 'si', {
|
||||
valueEncoding: 'json',
|
||||
db: down
|
||||
}, function (err, db) {
|
||||
SearchIndex.options.indexes = db
|
||||
return done(err, SearchIndex)
|
||||
})
|
||||
} else {
|
||||
return done(null, SearchIndex)
|
||||
}
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = function (siOptions) {
|
||||
var siUtil = {}
|
||||
|
||||
siUtil.countDocs = function (callback) {
|
||||
var count = 0
|
||||
const gte = 'DOCUMENT' + siOptions.keySeparator
|
||||
const lte = 'DOCUMENT' + siOptions.keySeparator + siOptions.keySeparator
|
||||
siOptions.indexes.createReadStream({gte: gte, lte: lte})
|
||||
.on('data', function (data) {
|
||||
count++
|
||||
})
|
||||
.on('error', function (err) {
|
||||
return callback(err, null)
|
||||
})
|
||||
.on('end', function () {
|
||||
return callback(null, count)
|
||||
})
|
||||
}
|
||||
|
||||
siUtil.close = function (callback) {
|
||||
siOptions.indexes.close(function (err) {
|
||||
while (!siOptions.indexes.isClosed()) {
|
||||
// log not always working here- investigate
|
||||
if (siOptions.log) siOptions.log.info('closing...')
|
||||
}
|
||||
if (siOptions.indexes.isClosed()) {
|
||||
if (siOptions.log) siOptions.log.info('closed...')
|
||||
callback(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return siUtil
|
||||
}
|
@@ -4,7 +4,7 @@
|
||||
|
||||
const Promise = require('bluebird')
|
||||
const _ = require('lodash')
|
||||
const searchIndex = require('./search-index')
|
||||
// const searchIndex = require('./search-index')
|
||||
const stopWord = require('stopword')
|
||||
const streamToPromise = require('stream-to-promise')
|
||||
const searchAllowedChars = new RegExp('[^a-z0-9' + wiki.data.regex.cjk + wiki.data.regex.arabic + ' ]', 'g')
|
||||
@@ -22,7 +22,7 @@ module.exports = {
|
||||
init () {
|
||||
let self = this
|
||||
self._isReady = new Promise((resolve, reject) => {
|
||||
searchIndex({
|
||||
/*searchIndex({
|
||||
deletable: true,
|
||||
fieldedSearch: true,
|
||||
indexPath: 'wiki',
|
||||
@@ -39,7 +39,7 @@ module.exports = {
|
||||
resolve(true)
|
||||
})
|
||||
}
|
||||
})
|
||||
}) */
|
||||
})
|
||||
|
||||
return self
|
||||
|
Reference in New Issue
Block a user