Commit 1beb455
committed
Add support for precise absolute tapered start time
Adding two variables, specifying the beginning and the end of a tapered start
interval, measured in nanoseconds since epoch:
```
FAKETIME_TAPER_BEGIN_NSEC_SINCE_EPOCH
FAKETIME_TAPER_END_NSEC_SINCE_EPOCH
```
The behavior these implement is similar to what `FAKETIME_START_AFTER_SECONDS`
does, with a few key differences:
* timestamp is absolute, instead of being relative to process startup
* timestamp is specified in nanoseconds
* conversion interacts correctly with `utimes` family of functions
* conversion is tapered (see below), which makes mapping reversible (up to loss of precision)
The reason we want this feature is the following use case.
We run a large test suite under faketime. That test suite has access to
filesystem artifacts that were created prior to test start up.
Among those artifacts are some caches which are considered up to date
iff the timestamps of the files match what's recorded in a data structure.
This means that for those caches to be considered valid we need their
timestamps to not be fake.
The reason we can't use `FAKETIME_START_AFTER_SECONDS` directly is that the
test suite consists of multiple processes, for those processes to correctly
interact with each other they need a consistent timestamp mapping that is shared
between them. In fact the simplest bash script already behaves incorrectly
because the commands use different process start times.
```
touch old
LD_PRELOAD=... FAKETIME=+100d FAKETIME_START_AFTER_SECONDS=0 bash -c 'touch new; stat old new'
```
The expected behavior is that the timestamp of `old` is not rewritten,
while the timestamp of `new` is rewritten.
That is in fact achievable now:
```
FAKETIME_TAPER_BEGIN_NSEC_SINCE_EPOCH=$(date +%s%N)
sleep 0.1
FAKETIME_TAPER_END_NSEC_SINCE_EPOCH=$(date +%s%N)
FAKETIME=+100d FAKETIME_KEEP_BEFORE_NSEC_SINCE_EPOCH="$now_ns" bash -c 'touch new; stat old new'
```
What is tapering and why do we need it?
The idea is to make the time transition smooth instead of abrupt, gradually
increasing the offset amount from the start to the end of the tapering interval.
The reason we want this is to make the time mapping reversible (up to some
loss of precision). This means some programs that interact with the file system
will no longer be confused. For example, if you do the equivalent
of `touch -d "3 days ago"` and then read back the timestamp, you'll get
approximately the expected timestamp, instead of something completely off.1 parent 942b30e commit 1beb455
1 file changed
+181
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
343 | 348 | | |
344 | 349 | | |
345 | 350 | | |
| |||
1156 | 1161 | | |
1157 | 1162 | | |
1158 | 1163 | | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
1159 | 1291 | | |
1160 | 1292 | | |
1161 | 1293 | | |
| |||
1180 | 1312 | | |
1181 | 1313 | | |
1182 | 1314 | | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
1183 | 1322 | | |
1184 | 1323 | | |
1185 | 1324 | | |
| |||
1217 | 1356 | | |
1218 | 1357 | | |
1219 | 1358 | | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
1220 | 1364 | | |
1221 | 1365 | | |
1222 | 1366 | | |
| |||
1261 | 1405 | | |
1262 | 1406 | | |
1263 | 1407 | | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
1264 | 1413 | | |
1265 | 1414 | | |
1266 | 1415 | | |
| |||
2897 | 3046 | | |
2898 | 3047 | | |
2899 | 3048 | | |
| 3049 | + | |
| 3050 | + | |
| 3051 | + | |
| 3052 | + | |
| 3053 | + | |
| 3054 | + | |
| 3055 | + | |
| 3056 | + | |
| 3057 | + | |
| 3058 | + | |
| 3059 | + | |
| 3060 | + | |
| 3061 | + | |
| 3062 | + | |
| 3063 | + | |
| 3064 | + | |
| 3065 | + | |
| 3066 | + | |
2900 | 3067 | | |
2901 | 3068 | | |
2902 | 3069 | | |
| |||
3220 | 3387 | | |
3221 | 3388 | | |
3222 | 3389 | | |
3223 | | - | |
3224 | 3390 | | |
3225 | 3391 | | |
3226 | 3392 | | |
| |||
3373 | 3539 | | |
3374 | 3540 | | |
3375 | 3541 | | |
3376 | | - | |
| 3542 | + | |
| 3543 | + | |
| 3544 | + | |
| 3545 | + | |
| 3546 | + | |
| 3547 | + | |
| 3548 | + | |
| 3549 | + | |
| 3550 | + | |
| 3551 | + | |
| 3552 | + | |
| 3553 | + | |
| 3554 | + | |
| 3555 | + | |
3377 | 3556 | | |
3378 | 3557 | | |
3379 | 3558 | | |
| |||
0 commit comments