Skip to content

Commit

Permalink
#684 PR review - logging update
Browse files Browse the repository at this point in the history
  • Loading branch information
dk1844 committed Nov 16, 2022
1 parent 35d97d0 commit 1bfb6be
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions arangodb-foxx-services/src/main/services/prune-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/

import {aql, db} from '@arangodb'
import * as Logger from '../utils/logger'

export function pruneBefore(timestamp) {
console.log(`[Spline] Prune data before: ${timestamp}`)
Logger.info(`[Spline] Prune data before: ${timestamp}`)
const t0 = Date.now()

// STAGE 1: Cleanup event + edges to plans
Expand All @@ -33,7 +34,7 @@ export function pruneBefore(timestamp) {
`).toArray()

const t1 = Date.now()
console.log(`Purged ${refPlanIds.length} plans, ${t1 - t0} ms`)
Logger.info(`Purged ${refPlanIds.length} plans, ${t1 - t0} ms`)

// STAGE 2: No progressOf corresponding to executionPlan (Need to scan all plans, and progressOf foreach) -> delete executionPlan and related fields
// Option A - https://github.com/AbsaOSS/spline/issues/684#issuecomment-1311499371
Expand All @@ -51,7 +52,7 @@ export function pruneBefore(timestamp) {

const collections = ['executes', 'operation', 'follows', 'uses', 'expression', 'affects', 'depends', 'writesTo', 'readsFrom', 'emits', 'produces', 'consistsOf', 'derivesFrom', 'computedBy', 'takes', 'schema', 'attribute']
for (let i = 0; i < collections.length; i++) {
console.log('### Working on', collections[i], 'collection')
Logger.info('### Working on', collections[i], 'collection')
const startCount = db._query('RETURN COUNT(@@cols)', {'@cols': collections[i]}).toArray()[0]
db._query('FOR orphanExecPlanID IN @arr FOR collectionEle IN @@cols FILTER collectionEle._belongsTo == orphanExecPlanID && collectionEle._created < @purgeLimitTimestamp REMOVE collectionEle IN @@cols',
{
Expand All @@ -61,28 +62,28 @@ export function pruneBefore(timestamp) {
}
)
const endCount = db._query('RETURN COUNT(@@cols)', {'@cols': collections[i]}).toArray()[0]
console.log(startCount - endCount, collections[i], 'objects deleted...')
Logger.info(startCount - endCount, collections[i], 'objects deleted...')
}

////////////////////////////////////////////////////////////////////////
// reused below
let startCount = 0
let endCount = 0

console.log('### Working on executionPlan collection')
Logger.info('### Working on executionPlan collection')
startCount = db._query('RETURN COUNT(@@cols)', {'@cols': 'executionPlan'}).toArray()[0]
db._query(aql`
FOR doc IN executionPlan
FILTER doc._id IN ${orphanExecPlanIDsOlderThanThresholdDaysArray}
REMOVE doc IN executionPlan
`)
endCount = db._query('RETURN COUNT(@@cols)', {'@cols': 'executionPlan'}).toArray()[0]
console.log(startCount - endCount, 'executionPlan objects deleted...')
Logger.info(startCount - endCount, 'executionPlan objects deleted...')

// Deleted other collections and then the orphanExecPlanIDs

const t2 = Date.now()
console.log(`All collections but dataSource purge in ${t2 - t1} ms`)
Logger.info(`All collections but dataSource purge in ${t2 - t1} ms`)

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -115,7 +116,7 @@ export function pruneBefore(timestamp) {
RETURN source._key
`).toArray()

console.log('### Working on dataSource collection')
Logger.info('### Working on dataSource collection')
startCount = db._query('RETURN COUNT(@@cols)', {'@cols': 'dataSource'}).toArray()[0]
db._query(aql`
FOR source IN dataSource
Expand All @@ -125,7 +126,7 @@ export function pruneBefore(timestamp) {
endCount = db._query('RETURN COUNT(@@cols)', {'@cols': 'dataSource'}).toArray()[0]

const t3 = Date.now()
console.log(startCount - endCount, `dataSource objects deleted... in ${t3 - t2} ms`)
console.log(`[Spline] Complete Prune time: ${t3 - t1} ms`)
console.log('-------Purge completed-------')
Logger.info(startCount - endCount, `dataSource objects deleted... in ${t3 - t2} ms`)
Logger.info(`[Spline] Complete Prune time: ${t3 - t1} ms`)
Logger.info('-------Purge completed-------')
}

0 comments on commit 1bfb6be

Please sign in to comment.