mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
[ProjectPersistenceManager] check all user content dirs for full disk
This commit is contained in:
parent
1127bf640e
commit
7380b54900
2 changed files with 36 additions and 23 deletions
|
@ -21,34 +21,45 @@ const logger = require('logger-sharelatex')
|
||||||
const oneDay = 24 * 60 * 60 * 1000
|
const oneDay = 24 * 60 * 60 * 1000
|
||||||
const Settings = require('settings-sharelatex')
|
const Settings = require('settings-sharelatex')
|
||||||
const diskusage = require('diskusage')
|
const diskusage = require('diskusage')
|
||||||
|
const { callbackify } = require('util')
|
||||||
|
|
||||||
module.exports = ProjectPersistenceManager = {
|
async function refreshExpiryTimeout() {
|
||||||
EXPIRY_TIMEOUT: Settings.project_cache_length_ms || oneDay * 2.5,
|
const paths = [
|
||||||
|
Settings.path.compilesDir,
|
||||||
refreshExpiryTimeout(callback) {
|
Settings.path.outputDir,
|
||||||
if (callback == null) {
|
Settings.path.clsiCacheDir
|
||||||
callback = function (error) {}
|
]
|
||||||
}
|
for (const path of paths) {
|
||||||
diskusage.check('/', function (err, stats) {
|
try {
|
||||||
if (err) {
|
const stats = await diskusage.check(path)
|
||||||
logger.err({ err: err }, 'error getting disk usage')
|
|
||||||
return callback(err)
|
|
||||||
}
|
|
||||||
const lowDisk = stats.available / stats.total < 0.1
|
const lowDisk = stats.available / stats.total < 0.1
|
||||||
|
|
||||||
const lowerExpiry = ProjectPersistenceManager.EXPIRY_TIMEOUT * 0.9
|
const lowerExpiry = ProjectPersistenceManager.EXPIRY_TIMEOUT * 0.9
|
||||||
if (lowDisk && Settings.project_cache_length_ms / 2 < lowerExpiry) {
|
if (lowDisk && Settings.project_cache_length_ms / 2 < lowerExpiry) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
{
|
{
|
||||||
stats: stats,
|
stats,
|
||||||
newExpiryTimeoutInDays: (lowerExpiry / oneDay).toFixed(2)
|
newExpiryTimeoutInDays: (lowerExpiry / oneDay).toFixed(2)
|
||||||
},
|
},
|
||||||
'disk running low on space, modifying EXPIRY_TIMEOUT'
|
'disk running low on space, modifying EXPIRY_TIMEOUT'
|
||||||
)
|
)
|
||||||
ProjectPersistenceManager.EXPIRY_TIMEOUT = lowerExpiry
|
ProjectPersistenceManager.EXPIRY_TIMEOUT = lowerExpiry
|
||||||
|
break
|
||||||
}
|
}
|
||||||
callback()
|
} catch (err) {
|
||||||
})
|
logger.err({ err, path }, 'error getting disk usage')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ProjectPersistenceManager = {
|
||||||
|
EXPIRY_TIMEOUT: Settings.project_cache_length_ms || oneDay * 2.5,
|
||||||
|
|
||||||
|
promises: {
|
||||||
|
refreshExpiryTimeout
|
||||||
},
|
},
|
||||||
|
|
||||||
|
refreshExpiryTimeout: callbackify(refreshExpiryTimeout),
|
||||||
markProjectAsJustAccessed(project_id, callback) {
|
markProjectAsJustAccessed(project_id, callback) {
|
||||||
if (callback == null) {
|
if (callback == null) {
|
||||||
callback = function (error) {}
|
callback = function (error) {}
|
||||||
|
|
|
@ -28,7 +28,12 @@ describe('ProjectPersistenceManager', function () {
|
||||||
'./CompileManager': (this.CompileManager = {}),
|
'./CompileManager': (this.CompileManager = {}),
|
||||||
diskusage: (this.diskusage = { check: sinon.stub() }),
|
diskusage: (this.diskusage = { check: sinon.stub() }),
|
||||||
'settings-sharelatex': (this.settings = {
|
'settings-sharelatex': (this.settings = {
|
||||||
project_cache_length_ms: 1000
|
project_cache_length_ms: 1000,
|
||||||
|
path: {
|
||||||
|
compilesDir: '/compiles',
|
||||||
|
outputDir: '/output',
|
||||||
|
clsiCacheDir: '/cache'
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
'./db': (this.db = {})
|
'./db': (this.db = {})
|
||||||
}
|
}
|
||||||
|
@ -40,7 +45,7 @@ describe('ProjectPersistenceManager', function () {
|
||||||
|
|
||||||
describe('refreshExpiryTimeout', function () {
|
describe('refreshExpiryTimeout', function () {
|
||||||
it('should leave expiry alone if plenty of disk', function (done) {
|
it('should leave expiry alone if plenty of disk', function (done) {
|
||||||
this.diskusage.check.callsArgWith(1, null, {
|
this.diskusage.check.resolves({
|
||||||
available: 40,
|
available: 40,
|
||||||
total: 100
|
total: 100
|
||||||
})
|
})
|
||||||
|
@ -54,7 +59,7 @@ describe('ProjectPersistenceManager', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should drop EXPIRY_TIMEOUT 10% if low disk usage', function (done) {
|
it('should drop EXPIRY_TIMEOUT 10% if low disk usage', function (done) {
|
||||||
this.diskusage.check.callsArgWith(1, null, {
|
this.diskusage.check.resolves({
|
||||||
available: 5,
|
available: 5,
|
||||||
total: 100
|
total: 100
|
||||||
})
|
})
|
||||||
|
@ -66,7 +71,7 @@ describe('ProjectPersistenceManager', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not drop EXPIRY_TIMEOUT to below 50% of project_cache_length_ms', function (done) {
|
it('should not drop EXPIRY_TIMEOUT to below 50% of project_cache_length_ms', function (done) {
|
||||||
this.diskusage.check.callsArgWith(1, null, {
|
this.diskusage.check.resolves({
|
||||||
available: 5,
|
available: 5,
|
||||||
total: 100
|
total: 100
|
||||||
})
|
})
|
||||||
|
@ -78,10 +83,7 @@ describe('ProjectPersistenceManager', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not modify EXPIRY_TIMEOUT if there is an error getting disk values', function (done) {
|
it('should not modify EXPIRY_TIMEOUT if there is an error getting disk values', function (done) {
|
||||||
this.diskusage.check.callsArgWith(1, 'Error', {
|
this.diskusage.check.throws(new Error())
|
||||||
available: 5,
|
|
||||||
total: 100
|
|
||||||
})
|
|
||||||
this.ProjectPersistenceManager.refreshExpiryTimeout(() => {
|
this.ProjectPersistenceManager.refreshExpiryTimeout(() => {
|
||||||
this.ProjectPersistenceManager.EXPIRY_TIMEOUT.should.equal(1000)
|
this.ProjectPersistenceManager.EXPIRY_TIMEOUT.should.equal(1000)
|
||||||
done()
|
done()
|
||||||
|
|
Loading…
Reference in a new issue