Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #62 from Unity-Technologies/release/6.1.2
Browse files Browse the repository at this point in the history
Release/6.1.2
  • Loading branch information
stephen-palmer authored Sep 26, 2018
2 parents d710bf5 + 96b312f commit d3361d6
Show file tree
Hide file tree
Showing 22 changed files with 834 additions and 669 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ node_modules/
coverage/
local-production.yml
.cache*/
Dockerfile*
.dockerignore
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v8.11.3
v8.12.0
9 changes: 2 additions & 7 deletions lib/cache/cache_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class CacheFS extends CacheBase {
let deleteSize = 0;
let deletedItemCount = 0;
let deleteItems = [];
let verb = dryRun ? 'Gathering' : 'Removing';
const verb = dryRun ? 'Gathering' : 'Removing';
let spinnerMessage = verb + ' expired files';

const progressData = () => {
Expand Down Expand Up @@ -184,7 +184,7 @@ class CacheFS extends CacheBase {
needsSorted = false;
}

let i = deleteItems[deleteItems.length - 1]; // i is the MRU out of the current delete list
const i = deleteItems[deleteItems.length - 1]; // i is the MRU out of the current delete list

if (item.stats.atime < i.stats.atime) {
deleteItems = helpers.insertSorted(item, deleteItems, (a, b) => {
Expand Down Expand Up @@ -361,11 +361,6 @@ class HashedWriteStream extends fs.WriteStream {
super._write(data, encoding, cb);
}

_writev (chunks, cb) {
chunks.forEach(chunk => this._hash.update(chunk, 'ascii'));
super._writev(chunks, cb);
}

get byteHash() {
return this._hash.digest();
}
Expand Down
2 changes: 2 additions & 0 deletions lib/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class CacheClient {
* @returns {Promise<any>}
*/
quit() {
if(!this._client) return Promise.resolve();

return new Promise(resolve => {
this._client.once('close', () => resolve());
this._client.end(cmd.quit);
Expand Down
19 changes: 13 additions & 6 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const consts = require("./constants");
const dns = require('dns');
const path = require('path');
const fs = require('fs-extra');
const ip = require('ip');

let logLevel = consts.LOG_TEST;

Expand Down Expand Up @@ -92,16 +93,23 @@ exports.isBuffer = function(obj) {
* @returns {Promise<any>}
*/
exports.parseAndValidateAddressString = function(address, defaultPort) {
if(ip.isV6Format(address) && !ip.isV4Format(address))
return Promise.reject("IPV6 mirrors not supported");

// eslint-disable-next-line prefer-const
let [host, port] = address.split(':');
port = port || defaultPort;

port = parseInt(port);
if(!port) port = defaultPort;

if(ip.isV4Format(host) || ip.isV6Format(host))
return Promise.resolve({ host: host, port: port });

return new Promise((resolve, reject) => {
dns.lookup(host, {family: 4, hints: dns.ADDRCONFIG}, (err, address) => {
dns.lookup(host, {family: 4, hints: dns.ADDRCONFIG}, (err, ip) => {
if(err) return reject(err);
resolve({ host: address, port: port });
resolve({ host: ip, port: port });
});
});
};
Expand Down Expand Up @@ -212,10 +220,9 @@ function locationOf(item, array, compare, start, end) {
start = start || 0;
end = end || array.length;

let pivot = (start + end) >> 1;

let c = compare(item, array[pivot]);
if (end - start <= 1) return c == -1 ? pivot - 1 : pivot;
const pivot = (start + end) >> 1;
const c = compare(item, array[pivot]);
if (end - start <= 1) return c === -1 ? pivot - 1 : pivot;

switch (c) {
case -1: return locationOf(item, array, compare, start, pivot);
Expand Down
7 changes: 4 additions & 3 deletions lib/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ class CacheServer {

const cmdProc = new CommandProcessor(self.cache);

// TODO: Prune mirror list to exclude the incoming socket address, to prevent looping transactions
const mirrors = self._mirrors;

if(mirrors.length > 0) {
cmdProc.on('onTransactionEnd', (trx) => {
mirrors.forEach(m => m.queueTransaction(trx));
mirrors.forEach(m => {
if(m.address !== socket.remoteAddress)
m.queueTransaction(trx);
});
});
}

Expand Down
10 changes: 6 additions & 4 deletions lib/server/transaction_mirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ class TransactionMirror {
this._cache = cache;
this._queue = [];
this._processing = false;
this._queueProcessDelay = TransactionMirror.options.queueProcessDelay || PROCESS_DELAY_MS;
this._queueProcessDelay = connectOptions.queueProcessDelay || TransactionMirror.options.queueProcessDelay || PROCESS_DELAY_MS;

const address = connectOptions.address;
const host = connectOptions.host;
const port = connectOptions.port;
const idleTimeout = TransactionMirror.options.idleTimeout || CONNECT_IDLE_TIMEOUT_MS;
this._client = new Client(address, port, {idleTimeout: idleTimeout});
const idleTimeout = connectOptions.idleTimeout || TransactionMirror.options.idleTimeout || CONNECT_IDLE_TIMEOUT_MS;
this._client = new Client(host, port, {idleTimeout: idleTimeout});
helpers.log(consts.LOG_INFO, `[TransactionMirror] Mirroring transactions to ${host}:${port}`);
}

static get options() {
Expand All @@ -38,6 +39,7 @@ class TransactionMirror {
}

_connect() {
helpers.log(consts.LOG_INFO, `[TransactionMirror] Connecting to ${this._connectOptions.host}:${this._connectOptions.port}`);
return this._client.connect();
}

Expand Down
4 changes: 2 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ function collect(val, memo) {
const defaultCacheModule = config.get("Cache.defaultModule");

const processorOptions = config.get("Cache.options.processor");
if(Array.isArray(processorOptions.putWhitelist) && processorOptions.putWhitelist.length){
if(Array.isArray(processorOptions.putWhitelist) && processorOptions.putWhitelist.length) {
helpers.log(consts.LOG_INFO, `PUT whitelist: ${processorOptions.putWhitelist}`);
};
}

program.description("Unity Cache Server")
.version(VERSION)
Expand Down
Loading

0 comments on commit d3361d6

Please sign in to comment.