Splitted Delay combination log from logging about it.

This commit is contained in:
Axel Kittenberger 2016-12-21 16:29:29 +01:00
parent ee50768743
commit 8e1a85a12d
3 changed files with 193 additions and 171 deletions

View File

@ -769,24 +769,6 @@ end )( )
-- --
local Combiner = ( function local Combiner = ( function
( ) ( )
--
-- The new delay is absorbed by an older one.
--
local function abso
(
d1, -- old delay
d2 -- new delay
)
log(
'Delay',
d2.etype, ': ',d2.path,
' absorbed by ',
d1.etype,': ',d1.path
)
return 'absorb'
end
-- --
-- The new delay replaces the old one if it's a file -- The new delay replaces the old one if it's a file
-- --
@ -818,78 +800,52 @@ local Combiner = ( function
return 'replace' return 'replace'
end end
--
-- The new delay replaces an older one.
--
local function repl
(
d1, -- old delay
d2 -- new delay
)
log(
'Delay',
d2.etype, ': ', d2.path,
' replaces ',
d1.etype, ': ', d1.path
)
return 'replace'
end
--
-- Two delays nullificate each other.
--
local function null
(
d1, -- old delay
d2 -- new delay
)
log(
'Delay',
d2.etype,': ',d2.path,
' nullifies ',
d1.etype,': ',d1.path
)
return 'remove'
end
-- --
-- Table on how to combine events that dont involve a move. -- Table on how to combine events that dont involve a move.
-- --
local combineNoMove = { local combineNoMove = {
Attrib = { Attrib = {
Attrib = abso, Attrib = 'absorb',
Modify = repl, Modify = 'replace',
Create = repl, Create = 'replace',
Delete = repl Delete = 'replace'
}, },
Modify = { Modify = {
Attrib = abso, Attrib = 'absorb',
Modify = abso, Modify = 'absorb',
Create = repl, Create = 'replace',
Delete = repl Delete = 'replace'
}, },
Create = { Create = {
Attrib = abso, Attrib = 'absorb',
Modify = abso, Modify = 'absorb',
Create = abso, Create = 'absorb',
Delete = repl Delete = 'replace'
}, },
Delete = { Delete = {
Attrib = abso, Attrib = 'absorb',
Modify = abso, Modify = 'absorb',
Create = refi, Create = 'replace file,block dir',
Delete = abso Delete = 'absorb'
}, },
} }
-- --
-- Combines two delays -- Returns the way two Delay should be combined.
--
-- Result:
-- nil -- They don't affect each other.
-- 'stack' -- Old Delay blocks new Delay.
-- 'replace' -- Old Delay is replaced by new Delay.
-- 'absorb' -- Old Delay absorbs new Delay.
-- 'toDelete,stack' -- Old Delay is turned into a Delete
-- and blocks the new Delay.
-- 'split' -- New Delay a Move is to be split
-- into a Create and Delete.
-- --
local function combine local function combine
( (
@ -898,25 +854,6 @@ local Combiner = ( function
) )
if d1.etype == 'Init' or d1.etype == 'Blanket' if d1.etype == 'Init' or d1.etype == 'Blanket'
then then
-- everything is blocked by init or blanket delays.
if d2.path2
then
log(
'Delay',
d2.etype, ': ',
d2.path, '->', d2.path2,
' blocked by ',
d1.etype, ': ', d1.path
)
else
log(
'Delay',
d2.etype, ': ', d2.path,
' blocked by ',
d1.etype, ': ', d1.path
)
end
return 'stack' return 'stack'
end end
@ -925,34 +862,25 @@ local Combiner = ( function
then then
if d1.path == d2.path if d1.path == d2.path
then then
if d1.status == 'active'
then
log(
'Delay',
d2.etype, ': ', d2.path,
' blocked by active ',
d1.etype, ': ', d1.path
)
return 'stack'
end
-- lookups up the function in the combination matrix -- lookups up the function in the combination matrix
-- and calls it -- and calls it
return combineNoMove[ d1.etype ][ d2.etype ]( d1, d2 ) local result = combineNoMove[ d1.etype ][ d2.etype ]
if result == 'replace file,block dir'
then
if d2.path:byte( -1 ) == 47
then
return 'stack'
else
return 'replace'
end
end
end end
-- if one is a parent directory of another, events are blocking -- if one is a parent directory of another, events are blocking
if d1.path:byte( -1 ) == 47 and string.starts( d2.path, d1.path ) if d1.path:byte( -1 ) == 47 and string.starts( d2.path, d1.path )
or d2.path:byte( -1 ) == 47 and string.starts( d1.path, d2.path ) or d2.path:byte( -1 ) == 47 and string.starts( d1.path, d2.path )
then then
log(
'Delay',
d2.etype, ': ', d2.path,
' blocked by parenting ',
d1.etype, ': ', d1.path
)
return 'stack' return 'stack'
end end
@ -967,13 +895,6 @@ local Combiner = ( function
or d2.path:byte( -1 ) == 47 and string.starts( d1.path, d2.path ) or d2.path:byte( -1 ) == 47 and string.starts( d1.path, d2.path )
or d1.path:byte( -1 ) == 47 and string.starts( d2.path, d1.path ) or d1.path:byte( -1 ) == 47 and string.starts( d2.path, d1.path )
then then
log(
'Delay',
d2.etype, ': ', d2.path,
' blocked by Move: ',
d1.path,' -> ', d1.path2
)
return 'stack' return 'stack'
end end
@ -986,53 +907,19 @@ local Combiner = ( function
then then
if d1.status == 'active' if d1.status == 'active'
then then
log(
'Delay',
d2.etype,': ',d2.path,
' blocked by active Move: ',
d1.path,' -> ', d1.path2
)
return 'stack' return 'stack'
end end
log(
'Delay',
d2.etype, ': ', d2.path,
' turns ',
'Move: ', d1.path, ' -> ', d1.path2,
' into ',
'Delete: ', d1.path
)
d1.etype = 'Delete'
d1.path2 = nil
return 'toDelete,stack' return 'toDelete,stack'
end end
-- on 'Attrib' or 'Modify' simply stack on moves -- on 'Attrib' or 'Modify' simply stack on moves
log(
'Delay',
d2.etype,': ',d2.path,
' blocked by Move: ',
d1.path,' -> ', d1.path2
)
return 'stack' return 'stack'
end end
if d2.path:byte( -1 ) == 47 and string.starts( d1.path2, d2.path ) if d2.path:byte( -1 ) == 47 and string.starts( d1.path2, d2.path )
or d1.path2:byte( -1 ) == 47 and string.starts( d2.path, d1.path2 ) or d1.path2:byte( -1 ) == 47 and string.starts( d2.path, d1.path2 )
then then
log(
'Delay'
,d2.etype, ': ', d2.path,
' blocked by Move: ',
d1.path, ' -> ', d1.path2
)
return 'stack' return 'stack'
end end
@ -1049,14 +936,6 @@ local Combiner = ( function
or d2.path:byte( -1 ) == 47 and string.starts( d1.path, d2.path ) or d2.path:byte( -1 ) == 47 and string.starts( d1.path, d2.path )
or d2.path2:byte( -1 ) == 47 and string.starts( d1.path, d2.path2 ) or d2.path2:byte( -1 ) == 47 and string.starts( d1.path, d2.path2 )
then then
log(
'Delay',
'Move: ',
d2.path, ' -> ', d2.path2,
' splits on ',
d1.etype, ': ', d1.path
)
return 'split' return 'split'
end end
@ -1082,14 +961,6 @@ local Combiner = ( function
or d2.path2:byte( -1 ) == 47 and string.starts( d1.path, d2.path2 ) or d2.path2:byte( -1 ) == 47 and string.starts( d1.path, d2.path2 )
or d2.path2:byte( -1 ) == 47 and string.starts( d1.path2, d2.path2 ) or d2.path2:byte( -1 ) == 47 and string.starts( d1.path2, d2.path2 )
then then
log(
'Delay',
'Move: ',
d2.path, ' -> ', d1.path2,
' splits on Move: ',
d1.path, ' -> ', d1.path2
)
return 'split' return 'split'
end end
@ -1100,10 +971,159 @@ local Combiner = ( function
end end
--
-- The new delay is absorbed by an older one.
--
local function logAbsorb
(
d1, -- old delay
d2 -- new delay
)
log(
'Delay',
d2.etype, ': ',d2.path,
' absorbed by ',
d1.etype,': ',d1.path
)
end
--
-- The new delay replaces the old one if it's a file.
--
local function logReplace
(
d1, -- old delay
d2 -- new delay
)
log(
'Delay',
d2.etype, ': ', d2.path,
' replaces ',
d1.etype, ': ', d1.path
)
end
--
-- The new delay splits on the old one.
--
local function logSplit
(
d1, -- old delay
d2 -- new delay
)
log(
'Delay',
d2.etype, ': ',
d2.path, ' -> ', d2.path2,i
' splits on ',
d1.etype, ': ', d1.path
)
end
--
-- The new delay is blocked by the old delay.
--
local function logStack
(
d1, -- old delay
d2 -- new delay
)
local active = ''
if d1.active
then
active = 'active '
end
if d2.path2
then
log(
'Delay',
d2.etype, ': ',
d2.path, '->', d2.path2,
' blocked by ',
active,
d1.etype, ': ', d1.path
)
else
log(
'Delay',
d2.etype, ': ', d2.path,
' blocked by ',
active,
d1.etype, ': ', d1.path
)
end
end
--
-- The new delay turns the old one (a move) into a delete and is blocked.
--
local function logToDeleteStack
(
d1, -- old delay
d2 -- new delay
)
if d1.path2
then
log(
'Delay',
d2.etype, ': ', d2.path,
' turns ',
d1.etype, ': ', d1.path, ' -> ', d1.path2,
' into Delete: ', d1.path
)
else
log(
'Delay',
d2.etype, ': ', d2.path,
' turns ',
d1.etype, ': ', d1.path,
' into Delete: ', d1.path
)
end
end
local logFuncs =
{
absorb = logAbsorb,
replace = logReplace,
split = logSplit,
stack = logStack,
[ 'toDelete,stack' ] = logToDeleteStack
}
--
-- Prints the log message for a combination result
--
local function log
(
result, -- the combination result
d1, -- old delay
d2 -- new delay
)
local lf = logFuncs[ result ]
if not lf
then
error( 'unknown combination result: ' .. result )
end
lf( d1, d2 )
end
-- --
-- Public interface -- Public interface
-- --
return { combine = combine } return
{
combine = combine,
log = log
}
end )( ) end )( )
@ -2403,6 +2423,8 @@ local Sync = ( function
if ac if ac
then then
Combiner.log( ac, od, nd )
if ac == 'remove' if ac == 'remove'
then then
self.delays:remove( il ) self.delays:remove( il )

View File

@ -15,7 +15,7 @@ cwriteln( '( for current user )' )
local tdir, srcdir, trgdir = mktemps() local tdir, srcdir, trgdir = mktemps()
-- makes some startup data -- makes some startup data
churn( srcdir, 10, true ) churn( srcdir, 5, true )
local logs = {} local logs = {}
logs = { '-log', 'Delay' } logs = { '-log', 'Delay' }
@ -35,7 +35,7 @@ local pid = spawn(
cwriteln( 'waiting for Lsyncd to startup' ) cwriteln( 'waiting for Lsyncd to startup' )
posix.sleep( 1 ) posix.sleep( 1 )
churn( srcdir, 15, false ) churn( srcdir, 50, false )
cwriteln( 'waiting for Lsyncd to finish its jobs.' ) cwriteln( 'waiting for Lsyncd to finish its jobs.' )
posix.sleep( 10 ) posix.sleep( 10 )

View File

@ -475,7 +475,7 @@ function churn
else else
dice = dice =
{ {
{ 10, sleep }, { 50, sleep },
{ 20, mkfile }, { 20, mkfile },
{ 20, mkdir }, { 20, mkdir },
{ 20, mvdir }, { 20, mvdir },