Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: add *timeNs properties to BigInt Stats objects #21387

Closed
wants to merge 1 commit into from

Conversation

joyeecheung
Copy link
Member

  • Extend the aliased buffer for stats objects to contain
    the entire time spec (seconds and nanoseconds) for the time
    values instead of calculating the milliseconds in C++ and
    lose precision.
  • Calculate the nanosecond-precision time values in JS and expose
    them in BigInt Stats objects as *timeNs. The
    millisecond-precision values are now calculated from the
    nanosecond-precision values.
  • Refactor the hierarchy of stats objects and use ES6 classes.
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. labels Jun 18, 2018
@joyeecheung
Copy link
Member Author

doc/api/fs.md Outdated Show resolved Hide resolved
doc/api/fs.md Outdated Show resolved Hide resolved
Copy link
Contributor

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it. One nit.

nsFromTimeSpecBigInt(stats[14 + offset], stats[15 + offset]),
nsFromTimeSpecBigInt(stats[16 + offset], stats[17 + offset])
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else would a touch clearer

Copy link
Member Author

@joyeecheung joyeecheung Jun 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fishrock123 I think we prefer leaving out the else block for early returns? There used to a PR adding a lint rule for that although it didn't land due to the amount of churn.

@jasnell jasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Jun 21, 2018
@jasnell
Copy link
Member

jasnell commented Jun 21, 2018

While I'm good with this, changing fs.Stats to a ES6 class is necessarily a semver-major change because fs.Stats() is no longer callable without new.

@jasnell
Copy link
Member

jasnell commented Jun 22, 2018

Just a thought... we may want to consider adding a custom toJSON() function to the BitIntStats object to avoid...

> JSON.stringify(fs.statSync('.', { bigint: true }))
TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)

@joyeecheung
Copy link
Member Author

JSON.stringify(fs.statSync('.', { bigint: true }))
TypeError: Do not know how to serialize a BigInt
at JSON.stringify ()

@jasnell hm, thanks for raising that up, but we need to be careful about the format we pick since people may store them into DB or send them to clients that are not implemented in JavaScript...

@joyeecheung joyeecheung added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jun 26, 2018
@joyeecheung
Copy link
Member Author

On a second thought, the ES6 classes probably does not worth making this semver major. I have changed it back to the ES5 way of doing things. @jasnell

@joyeecheung joyeecheung removed the semver-major PRs that contain breaking changes and should be released in the next major version. label Jun 27, 2018
@joyeecheung
Copy link
Member Author

joyeecheung commented Jun 27, 2018

@joyeecheung
Copy link
Member Author

joyeecheung commented Jul 5, 2018

Ping @jasnell does this look good to you now as a non-semver-major?

@jasnell
Copy link
Member

jasnell commented Jul 10, 2018

Yes, looks good

@addaleax
Copy link
Member

Previous CI is inaccessible, new CI: https://ci.nodejs.org/job/node-test-pull-request/15855/

@Trott
Copy link
Member

Trott commented Jul 18, 2018

@joyeecheung
Copy link
Member Author

Looks like it broke something related to #13255 on Windows, I'll investigate.

Failures in job https://ci.nodejs.org/job/node-test-pull-request/15920/

debian8-x86

See failures on test-softlayer-debian8-x86-1:
not ok 658 parallel/test-fs-utimes
  ---
  duration_ms: 0.331
  severity: fail
  exitcode: 1
  stack: |-
    assert.js:84
      throw new AssertionError(obj);
      ^
    
    AssertionError [ERR_ASSERTION]: Input A expected to strictly equal input B:
    + expected - actual
    
    - 2147483648
    + -2147483647.999
        at Object.<anonymous> (/home/iojs/build/workspace/node-test-commit-linux/nodes/debian8-x86/test/parallel/test-fs-utimes.js:196:10)
        at Module._compile (internal/modules/cjs/loader.js:689:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
        at Module.load (internal/modules/cjs/loader.js:599:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
        at Function.Module._load (internal/modules/cjs/loader.js:530:3)
        at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
        at startup (internal/bootstrap/node.js:266:19)
        at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
  ...

ubuntu1404-32

See failures on test-digitalocean-ubuntu1404-x86-1:
not ok 601 parallel/test-fs-utimes
  ---
  duration_ms: 0.629
  severity: fail
  exitcode: 1
  stack: |-
    assert.js:84
      throw new AssertionError(obj);
      ^
    
    AssertionError [ERR_ASSERTION]: Input A expected to strictly equal input B:
    + expected - actual
    
    - 2147483648
    + -2147483647.999
        at Object.<anonymous> (/home/iojs/build/workspace/node-test-commit-linux/nodes/ubuntu1404-32/test/parallel/test-fs-utimes.js:196:10)
        at Module._compile (internal/modules/cjs/loader.js:689:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
        at Module.load (internal/modules/cjs/loader.js:599:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
        at Function.Module._load (internal/modules/cjs/loader.js:530:3)
        at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
        at startup (internal/bootstrap/node.js:266:19)
        at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
  ...

ubuntu1604-32

See failures on test-digitalocean-ubuntu1604-x86-2:
not ok 658 parallel/test-fs-utimes
  ---
  duration_ms: 0.171
  severity: fail
  exitcode: 1
  stack: |-
    assert.js:84
      throw new AssertionError(obj);
      ^
    
    AssertionError [ERR_ASSERTION]: Input A expected to strictly equal input B:
    + expected - actual
    
    - 2147483648
    + -2147483647.999
        at Object.<anonymous> (/home/iojs/build/workspace/node-test-commit-linux/nodes/ubuntu1604-32/test/parallel/test-fs-utimes.js:196:10)
        at Module._compile (internal/modules/cjs/loader.js:689:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
        at Module.load (internal/modules/cjs/loader.js:599:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
        at Function.Module._load (internal/modules/cjs/loader.js:530:3)
        at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
        at startup (internal/bootstrap/node.js:266:19)
        at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
  ...

COMPILED_BY=vs2017,RUNNER=win10,RUN_SUBSET=3

See failures on test-azure_msft-win10-x64-3:
not ok 165 parallel/test-fs-utimes
  ---
  duration_ms: 0.121
  severity: fail
  exitcode: 1
  stack: |-
    assert.js:84
      throw new AssertionError(obj);
      ^
    
    AssertionError [ERR_ASSERTION]: Input A expected to strictly equal input B:
    + expected - actual
    
    - 2147483648
    + -2147483647.999
        at Object.<anonymous> (c:\workspace\node-test-binary-windows\test\parallel\test-fs-utimes.js:196:10)
        at Module._compile (internal/modules/cjs/loader.js:689:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
        at Module.load (internal/modules/cjs/loader.js:599:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
        at Function.Module._load (internal/modules/cjs/loader.js:530:3)
        at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
        at startup (internal/bootstrap/node.js:266:19)
        at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
  ...

COMPILED_BY=vs2017,RUNNER=win2008r2-vs2017,RUN_SUBSET=3

See failures on test-rackspace-win2008r2-x64-3:
not ok 165 parallel/test-fs-utimes
  ---
  duration_ms: 0.198
  severity: fail
  exitcode: 1
  stack: |-
    assert.js:84
      throw new AssertionError(obj);
      ^
    
    AssertionError [ERR_ASSERTION]: Input A expected to strictly equal input B:
    + expected - actual
    
    - 2147483648
    + -2147483647.999
        at Object.<anonymous> (c:\workspace\node-test-binary-windows\test\parallel\test-fs-utimes.js:196:10)
        at Module._compile (internal/modules/cjs/loader.js:689:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
        at Module.load (internal/modules/cjs/loader.js:599:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
        at Function.Module._load (internal/modules/cjs/loader.js:530:3)
        at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
        at startup (internal/bootstrap/node.js:266:19)
        at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
  ...

COMPILED_BY=vs2017,RUNNER=win2016,RUN_SUBSET=3

See failures on test-azure_msft-win2016-x64-3:
not ok 165 parallel/test-fs-utimes
  ---
  duration_ms: 0.120
  severity: fail
  exitcode: 1
  stack: |-
    assert.js:84
      throw new AssertionError(obj);
      ^
    
    AssertionError [ERR_ASSERTION]: Input A expected to strictly equal input B:
    + expected - actual
    
    - 2147483648
    + -2147483647.999
        at Object.<anonymous> (c:\workspace\node-test-binary-windows\test\parallel\test-fs-utimes.js:196:10)
        at Module._compile (internal/modules/cjs/loader.js:689:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
        at Module.load (internal/modules/cjs/loader.js:599:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
        at Function.Module._load (internal/modules/cjs/loader.js:530:3)
        at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
        at startup (internal/bootstrap/node.js:266:19)
        at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
  ...

COMPILED_BY=vs2017-x86,RUNNER=win2012r2,RUN_SUBSET=3

See failures on test-rackspace-win2012r2-x64-1:
not ok 165 parallel/test-fs-utimes
  ---
  duration_ms: 0.203
  severity: fail
  exitcode: 1
  stack: |-
    assert.js:84
      throw new AssertionError(obj);
      ^
    
    AssertionError [ERR_ASSERTION]: Input A expected to strictly equal input B:
    + expected - actual
    
    - 2147483648
    + -2147483647.999
        at Object.<anonymous> (c:\workspace\node-test-binary-windows\test\parallel\test-fs-utimes.js:196:10)
        at Module._compile (internal/modules/cjs/loader.js:689:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
        at Module.load (internal/modules/cjs/loader.js:599:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
        at Function.Module._load (internal/modules/cjs/loader.js:530:3)
        at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
        at startup (internal/bootstrap/node.js:266:19)
        at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
  ...

@BridgeAR BridgeAR removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 18, 2018
@joyeecheung
Copy link
Member Author

Won't be able to be around a machine to look into this this week

@jasnell
Copy link
Member

jasnell commented Sep 10, 2018

What's the status on this one?

@jasnell jasnell added the stalled Issues and PRs that are stalled. label Sep 10, 2018
@josepharhar
Copy link

Can we try fixing merge conflicts and running the tests again? I'd be happy to give it a shot in another pull request

- Extend the aliased buffer for stats objects to contain
  the entire time spec (seconds and nanoseconds) for the time
  values instead of calculating the milliseconds in C++ and
  lose precision there.
- Calculate the nanosecond-precision time values in JS and expose
  them in BigInt Stats objects as `*timeNs`. The
  millisecond-precision values are now calculated from the
  nanosecond-precision values.
@joyeecheung
Copy link
Member Author

@joyeecheung joyeecheung removed the stalled Issues and PRs that are stalled. label Jun 11, 2019
stats[3 + offset], stats[4 + offset], stats[5 + offset],
stats[6 + offset], stats[7 + offset], stats[8 + offset],
stats[9 + offset],
msFromTimeSpec(stats[10 + offset], stats[11 + offset]),
Copy link
Member Author

@joyeecheung joyeecheung Jun 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't pass a time spec into the Stats constructor as that would be a breaking change since Stats is public. We may try using some factory function to construct Stats internally from time specs later, and try adding the Ns properties to normal Stats later, though, but there will be some precision losses without bigint and that's not too different from multiplying the Ms ones with 1000

@joyeecheung
Copy link
Member Author

The CI is now green (minus an unrelated failure #27611 )

@jasnell @Fishrock123 can you please take a look again?

Also @devsnek this might be useful for #27850 , whichever lands first..

@@ -726,6 +731,54 @@ added: v8.1.0
The timestamp indicating the creation time of this file expressed in
milliseconds since the POSIX Epoch.

### stats.atimeNs
<!-- YAML
added: REPLACEME
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be changed, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'll only be available when this is released.

@joyeecheung
Copy link
Member Author

@joyeecheung
Copy link
Member Author

Landed in b245257

@joyeecheung joyeecheung added semver-minor PRs that contain new features and should be released in the next minor version. and removed review wanted PRs that need reviews. labels Jun 13, 2019
joyeecheung added a commit that referenced this pull request Jun 13, 2019
- Extend the aliased buffer for stats objects to contain
  the entire time spec (seconds and nanoseconds) for the time
  values instead of calculating the milliseconds in C++ and
  lose precision there.
- Calculate the nanosecond-precision time values in JS and expose
  them in BigInt Stats objects as `*timeNs`. The
  millisecond-precision values are now calculated from the
  nanosecond-precision values.

PR-URL: #21387
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
BridgeAR pushed a commit that referenced this pull request Jun 17, 2019
- Extend the aliased buffer for stats objects to contain
  the entire time spec (seconds and nanoseconds) for the time
  values instead of calculating the milliseconds in C++ and
  lose precision there.
- Calculate the nanosecond-precision time values in JS and expose
  them in BigInt Stats objects as `*timeNs`. The
  millisecond-precision values are now calculated from the
  nanosecond-precision values.

PR-URL: #21387
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
@BridgeAR BridgeAR mentioned this pull request Jun 17, 2019
@targos targos mentioned this pull request Aug 19, 2019
2 tasks
BridgeAR pushed a commit that referenced this pull request Sep 3, 2019
- Extend the aliased buffer for stats objects to contain
  the entire time spec (seconds and nanoseconds) for the time
  values instead of calculating the milliseconds in C++ and
  lose precision there.
- Calculate the nanosecond-precision time values in JS and expose
  them in BigInt Stats objects as `*timeNs`. The
  millisecond-precision values are now calculated from the
  nanosecond-precision values.

PR-URL: #21387
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
@BridgeAR BridgeAR mentioned this pull request Sep 3, 2019
BridgeAR added a commit that referenced this pull request Sep 3, 2019
Notable changes:

* deps:
  * Update npm to 6.10.3 (isaacs)
    #29023
* fs:
  * Add recursive option to rmdir() (cjihrig)
    #29168
  * Allow passing true to emitClose option (Giorgos Ntemiris)
    #29212
  * Add \*timeNs properties to BigInt Stats objects (Joyee Cheung)
    #21387
* net:
  * Allow reading data into a static buffer (Brian White)
    #25436

PR-URL: #29429
BridgeAR added a commit that referenced this pull request Sep 4, 2019
Notable changes:

* deps:
  * Update npm to 6.10.3 (isaacs)
    #29023
* fs:
  * Add recursive option to rmdir() (cjihrig)
    #29168
  * Allow passing true to emitClose option (Giorgos Ntemiris)
    #29212
  * Add \*timeNs properties to BigInt Stats objects (Joyee Cheung)
    #21387
* net:
  * Allow reading data into a static buffer (Brian White)
    #25436

PR-URL: #29429
BridgeAR added a commit that referenced this pull request Sep 4, 2019
Notable changes:

* deps:
  * Update npm to 6.10.3 (isaacs)
    #29023
* fs:
  * Add recursive option to rmdir() (cjihrig)
    #29168
  * Allow passing true to emitClose option (Giorgos Ntemiris)
    #29212
  * Add \*timeNs properties to BigInt Stats objects (Joyee Cheung)
    #21387
* net:
  * Allow reading data into a static buffer (Brian White)
    #25436

PR-URL: #29429
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.