Add safe manual instance rebalancing
This commit is contained in:
@@ -45,6 +45,34 @@ it('expires completed file payloads while keeping history, replay identity, hold
|
||||
expect(pruneHistory('operation-payload')).toBe(0);
|
||||
});
|
||||
|
||||
it('retains rebalance recovery files until the move is reconciled, then lets history expire', async () => {
|
||||
const { db } = await import('../../src/lib/server/db/index.js');
|
||||
const { ensureHostSchema } = await import('../../src/lib/server/hosts/schema.js');
|
||||
const { pruneHistory } = await import('../../src/lib/server/retention.js');
|
||||
const { putFileBlob } = await import('../../src/lib/server/db/file-blobs.js');
|
||||
const { fleetSettings, saveFleetSettings } = await import('../../src/lib/server/settings.js');
|
||||
ensureHostSchema(db());
|
||||
saveFleetSettings({ ...fleetSettings(), historyKeepCount: 0, provisioningKeepDays: 1, payloadKeepDays: 1 });
|
||||
db().prepare(`INSERT INTO server_deployments(id,server,action,state,stage,started_at,finished_at,triggered_by)
|
||||
VALUES('move','s','rebuild','done','healthy',?,?,'rebalance:run')`).run(old, old);
|
||||
const hash = putFileBlob(Buffer.from('frozen deployed file'));
|
||||
db().prepare('INSERT INTO server_launch_recipes(deployment_id,recipe) VALUES(?,?)')
|
||||
.run('move', JSON.stringify({ files: [{ path: 'script.gsc', sha256: hash, contentHash: hash }] }));
|
||||
db().prepare(`INSERT INTO rebalancing_runs(id,settings,state,created_at,updated_at,message)
|
||||
VALUES('run','{}','running',?,?,'waiting')`).run(old, old);
|
||||
db().prepare(`INSERT INTO rebalancing_moves(id,run_id,ordinal,server,instance_id,generation,source_host_id,target_host_id,candidate,state,operation_id,message,updated_at)
|
||||
VALUES('m','run',0,'s','i',1,'a','b','{}','moving','move','waiting',?)`).run(old);
|
||||
expect(pruneHistory('workflow-payload')).toBe(0);
|
||||
expect(pruneHistory('provisioning')).toBe(0);
|
||||
db().prepare("UPDATE rebalancing_moves SET state='failed'").run();
|
||||
expect(pruneHistory('workflow-payload')).toBe(0);
|
||||
expect(pruneHistory('provisioning')).toBe(0);
|
||||
db().prepare("UPDATE rebalancing_moves SET state='done'").run();
|
||||
expect(pruneHistory('workflow-payload')).toBe(1);
|
||||
expect(pruneHistory('provisioning')).toBe(1);
|
||||
expect(db().prepare('SELECT state,operation_id FROM rebalancing_moves').get()).toEqual({ state: 'done', operation_id: null });
|
||||
});
|
||||
|
||||
it('normalizes legacy retention clocks once and reuses clock indexes', () => {
|
||||
const handle = new Database(':memory:');
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user