Skip to content

Conversation

@pravindra
Copy link
Contributor

No description provided.

@codecov-io
Copy link

codecov-io commented Dec 25, 2018

Codecov Report

Merging #3246 into master will increase coverage by 0.76%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3246      +/-   ##
==========================================
+ Coverage    88.5%   89.27%   +0.76%     
==========================================
  Files         539      384     -155     
  Lines       72968    48981   -23987     
==========================================
- Hits        64583    43728   -20855     
+ Misses       8278     5253    -3025     
+ Partials      107        0     -107
Impacted Files Coverage Δ
cpp/src/arrow/csv/reader.h 0% <0%> (-100%) ⬇️
cpp/src/arrow/csv/reader.cc 0.52% <0%> (-90.48%) ⬇️
cpp/src/gandiva/function_holder_registry.h 0% <0%> (-80%) ⬇️
cpp/src/arrow/adapters/orc/adapter.cc 0.26% <0%> (-74.08%) ⬇️
cpp/src/plasma/eviction_policy.cc 59.01% <0%> (-40.99%) ⬇️
cpp/src/plasma/events.cc 52.5% <0%> (-35%) ⬇️
cpp/src/arrow/csv/options.h 66.66% <0%> (-33.34%) ⬇️
cpp/src/plasma/thirdparty/ae/ae.c 41.7% <0%> (-29.39%) ⬇️
cpp/src/plasma/thirdparty/dlmalloc.c 21.61% <0%> (-23.65%) ⬇️
cpp/src/arrow/vendored/xxhash/xxhash.c 51.26% <0%> (-22.34%) ⬇️
... and 212 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1291274...94a2015. Read the comment docs.

@pravindra pravindra changed the title ARROW-4104: [WIP] [Java] fix a race condition in AllocationManager ARROW-4104: [Java] fix a race condition in AllocationManager Dec 26, 2018
@pravindra
Copy link
Contributor Author

@siddharthteotia @jacques-n can you please review ?

  1. I changed the default allocation size to 3968 (from 4096) since allocating 4096 elements causes a wastage of at ~16K.
  2. Lot of tests assume an initial allocation of 4096 or 4095 - I've modified the tests to explicitly set the initial allocation size.
  3. fixed a race condition (bug in my earlier change)

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems more generic than necessary. Why not make it size aware and do the allocation based on a provided value count? Also, if int[] is always length two in usage, let's make it focus on that case. For example, we shouldn't be allocating the variable data chunk in the same vector since it will have a different lifecycle.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to use this for both fixed-len (data+validity) and var-len vectors (offsets+validity).

  • For the fixed-len vectors, the data buffers and validity buffers are sized for the same number-of-elements.
  • For the var-len vectors, the offset buffer needs to be sized for one extra element than the bitmap.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why this can't be generic just like the the original alloc with just valuecount *2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • even if the initial allocation was not a power-of-two allocation, I'm making the realloc switch to a power-of-2. most of the code deals with that.
  • during realloc, we need to memcpy from original buffer, and bzero the rest.

other than the above, the code is common (allocAndSlice).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thinking further, I think this can be simplified significantly if I make both the initial allocation and the reAlloc target a multiple-of-2 allocation.

I'll need to fix a lot of tests (the allocation may be larger than what was asked for), but it's probably worth the simplicity.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have this method at all? Shouldn't this be shared with the value buffer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is used by an api called setNull(int index) - it just sets the validity bit to false without actually adding a data element. If this optimization isn't useful, I can switch to expand both validity/offset arrays (I preserved the old behavior).

Also, used by another api setIndexDefined(int index). I think this one isn't meaningful unless we expand both the validity and the offset arrays.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we should always only resize together. If you resized the validity buffer, you'll need to resize the data buffer ultimately anyway (when you call setValueCount). We shouldn't be ever doing a partial resize.

@pravindra pravindra changed the title ARROW-4104: [Java] fix a race condition in AllocationManager ARROW-4104: [WIP] [Java] fix a race condition in AllocationManager Dec 27, 2018
@pravindra pravindra changed the title ARROW-4104: [WIP] [Java] fix a race condition in AllocationManager ARROW-4104: [Java] fix a race condition in AllocationManager Dec 31, 2018
@pravindra
Copy link
Contributor Author

pravindra commented Dec 31, 2018

@jacques-n - I've addressed the review comments. There is one change in behavior - both allocateNew and reAlloc can allocate more than the requested size, to ensure that the allocated buffer size is a power-of-2. Most of the test related changes are related to this.

can you please review now ?

Copy link
Contributor

@jacques-n jacques-n left a comment

Choose a reason for hiding this comment

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

You're commit message doesn't match your changes. Why are you making the other changes?

Copy link
Contributor

Choose a reason for hiding this comment

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

While we're here, we should update this message. The problem here is that we're trying to put more than X values in a record batch, which isn't allowed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be the rounded up value count?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, the value count isn't rounded up. The buffer size is rounded up to a power-of-2 when the allocation happens, and the buffer is then used to it's full capacity.

Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here about exception message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, are you asking more detail in the error message, like

B bytes of memory required for capacity of C values, which exceeds the max limit of L bytes

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this really allocFixedDataAndValidityBufs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will change name

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's return an object instead of an array.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just add the pre-checks to this method rather than have in other places.

valueCount between 0 and the value count allowed for a particular type.
type width 0 to 16 (right?)

Also, shouldn't we be returning the calculated valuecount? e.g. if you size for 50 but it turns out we can fit 60 in the same memory, shouldn't we be using that as the available size/value count (for initial alloc purposes, etc)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add the pre-checks.

Also, shouldn't we be returning the calculated valuecount? e.g. if you size for 50 but it turns > out we can fit 60 in the same memory, shouldn't we be using that as the available size/value > count (for initial alloc purposes, etc)?

That's done as part of allocDataAndValidityBufs (both for initial alloc and realloc) - in this case, it will return buffers with capacity of 60. And, the vector implementations will utilize the total capacity of 60.

The api setInitialCapacity() sets the variables based on whatever the user requests. Later, during alloc/realloc, the buffers allocated can have a capacity greater than this (power-of-2 roundup).

Copy link
Contributor

Choose a reason for hiding this comment

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

style nit: space between cast and expression

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix

@pravindra
Copy link
Contributor Author

You're commit message doesn't match your changes. Why are you making the other changes?

My initial change reduced the heap usage only for fixed-width vectors. This change extends the same fix for variable-width vectors, and the restructuring for code re-use. I'll open a separate lira for the variable-width vectors.

@pravindra
Copy link
Contributor Author

You're commit message doesn't match your changes. Why are you making the other changes?

My initial change reduced the heap usage only for fixed-width vectors. This change extends the same fix for variable-width vectors, and the restructuring for code re-use. I'll open a separate lira for the variable-width vectors.

I've opened ARROW-4147 for the rest of the change. Will use this to fix the race issue only.

@pravindra
Copy link
Contributor Author

@siddharthteotia @jacques-n - this PR now only has the fix for the race condition. Can you please merge this change ?

Copy link
Contributor

@siddharthteotia siddharthteotia left a comment

Choose a reason for hiding this comment

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

+1

@siddharthteotia siddharthteotia merged commit 55848a3 into apache:master Jan 8, 2019
@pravindra pravindra deleted the batch branch February 13, 2019 12:30
pribor pushed a commit to GlobalWebIndex/arrow that referenced this pull request Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants