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

Bug fixes, documentation (source level), and general cleanup #135

Merged
merged 29 commits into from
Aug 28, 2013
Merged

Bug fixes, documentation (source level), and general cleanup #135

merged 29 commits into from
Aug 28, 2013

Conversation

kspangsege
Copy link
Contributor

  • Correction of detection of changed arrays when updating accessors after Group::commit()
  • Fixed bug in TableViewBase::sort().
  • Add free space tracking to a database file that does not have it when calling Group::commit().
  • In Group::verify(), do not asssert that free space versioning is present just because it is opened in shared mode.
  • Stop throwing from destructors, and from SharedGroup::rollback() and SharedGRoup::end_read().
  • Avoid function local statics as they are not necessarily thread-safe.
  • In GroupWriter::reserve_free_space(), after looking in the last half of the list of free space hunks, look in the first half.
  • Avoid clobbering the previous database version in GroupWriter::commit() in the non-transactional case.
  • Eliminate the risk of extending byte size of Group::m_free_positions in GroupWriter::commit() after using its exact size in a calculation.
  • Eliminate unnecessary free space fragmentation by stopping GroupWriter::reserve_free_space() from adjusting the size of the identified chunk when it is different from the requested size.
  • GroupWriter::get_fre_space() and Group::Writer::reserve_free_space() now share searching code, and therefore, both skip the first part of the list when searching for a chunk that is larger than 1024 bytes.
  • Fixed an undetected free-space leak when deleting free-space version tracking in GroupWriter::commit().
  • More source level documentation.
  • Many other improvements.

\cc @bmunkholm @astigsen

Add free space tracking to a database file that does not have it when calling Group::commit().
In Group::verify(), do not asssert that free space versioning is present just because it is opened in shared mode.
…() in the non-transactional case.

Eliminate the risk of extending byte size of Group::m_free_positions in GroupWriter::commit() after using its exact size in a calculation.
Eliminate unnecessary free space fragmentation by stopping GroupWriter::reserve_free_space() from adjusting the size of the identified chunk when it is different from the requested size.
GroupWriter::get_fre_space() and Group::Writer::reserve_free_space() now share searching code, and therefore, both skip the first part of the list when searching for a chunk that is larger than 1024 bytes.
Fixed an undetected free-space leak when deleting free-space version tracking in GroupWriter::commit().
More documentation.
Many other improvements.
…f the list of free space hunks, look in the first half
…SharedGRoup::end_read().

Avoid function local statics as they are not necessarily thread-safe.
@ghost ghost assigned bmunkholm Aug 23, 2013
@rrrlasse
Copy link
Contributor

On Windows: test\testshared.cpp:904: error: Failure in Shared_MixedWithNonShared: Unhandled exception: CreateFile() failed: The system cannot find the path specified.


TEST(Shared_MixedWithNonShared)
{
File::try_remove("/tmp/x.tightdb");
Copy link
Contributor

Choose a reason for hiding this comment

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

/tmp can not be recommended as directory on Windows.
In general I think we should have a define/const for the path, and then use it in general. With this the files will be placed in two locations. For now it would be better to just skip "/tmp/"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. Fixed!

It was never my intention to use a path here. Slipped through from earlier experimentation.

Would it not be possible to configure Visual Studio such that it also runs the test suite with "/test/" as the current working directory?

@bmunkholm
Copy link
Contributor

That's a lot.... I recommend Lasse/Alexander review the Array and Group changes. I have not done that in detail.
Best suggestion is to add testcases that reveal the old bugs that are claimed fixed, and now proves they are fixed.

@kspangsege
Copy link
Contributor Author

  • Test suite passes on Linux and Darwin
  • Test suite passes on Windows except for the usual issues (Table_test_to_string, Table_test_json_all_data, Table_test_json_simple)
  • Extended test suite passes (tested on Linux.)
  • All language binding test suites pass.
  • No memory leaks in core library (tested on Linux.)
  • Valgrind reports no new issues (tested on Linux.)
  • No warnings with GCC 4.6, GCC 4.7, GCC 4.8, Clang 3.2, Clang 4.0.
  • No new warnings with Visual Studio.
  • Tested both with and without C++11 enabled (on Linux.)

Note that my tests on Windows are conducted under Virtual Box with zero SSE support enabled.

@kspangsege
Copy link
Contributor Author

Please note that the bulk of the changes revolve around the robustness of Group::commit(), and to a lesser extent, around the robustness of SharedGroup::commit().

In both cases, the robustness is already tested as much as it can be within the context of trivial unit testing. Here is how:

  1. In some cases,the error is already tested for, but occurs very rarely. Example: Correction of detection of changed arrays when updating accessors after Group::commit()
  2. In other cases, the problem could only materialize across an abrupt termination of the process at a critical place. While testing such things is possible, it is far from trivial. Example: Avoid clobbering the previous database version in GroupWriter::commit() in the non-transactional case
  3. In yet other cases, the fixed problem is all about efficiency and performance. Example: Eliminate unnecessary free space fragmentation by stopping GroupWriter::reserve_free_space() from adjusting the size of the identified chunk when it is different from the requested size

return const_cast<Group*>(this)->get_table_ptr<T>(name);
TIGHTDB_STATIC_ASSERT(IsBasicTable<T>::value, "Invalid table type");
const Table* table = get_table_ptr(name); // Throws
TIGHTDB_ASSERT(table || T::matches_dynamic_spec(&table->get_spec()));
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 it be an && here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good find. Actually it should have been "!table || ...". this is fixed in my upcoming commit.

@astigsen
Copy link
Contributor

Does not build on Xcode. File 'thread.cpp' is only member of 'libtightdb ios' and not 'libtightdb'. So you get errors from the linker for missing symbols.

Fixing that makes it build, but when trying to run the unit tests, it crashes on startup.

Call stack:

#0 0x000000010022d475 in tightdb::Array::create_empty_array(tightdb::Array::Type, tightdb::Array::WidthType, tightdb::Allocator&) at /Users/alexanderstigsen/Documents/Dev/tightdb/src/tightdb/array.cpp:1206
#1 0x00000001004748e2 in tightdb::Array::create_empty_array(tightdb::Array::Type, tightdb::Allocator&) at /Users/alexanderstigsen/Documents/Dev/tightdb/src/tightdb/array.hpp:1576
#2 0x000000010040c248 in tightdb::Array::create(tightdb::Array::Type) at /Users/alexanderstigsen/Documents/Dev/tightdb/src/tightdb/array.hpp:1068
#3 0x000000010047487c in tightdb::Array::Array(tightdb::Array::Type, tightdb::ArrayParent_, unsigned long, tightdb::Allocator&) at /Users/alexanderstigsen/Documents/Dev/tightdb/src/tightdb/array.hpp:1014
#4 0x000000010040c323 in tightdb::Array::Array(tightdb::Array::Type, tightdb::ArrayParent_, unsigned long, tightdb::Allocator&) at /Users/alexanderstigsen/Documents/Dev/tightdb/src/tightdb/array.hpp:1016
#5 0x0000000100038dbe in cxx_global_var_init at /Users/alexanderstigsen/Documents/Dev/tightdb/test/testarray.cpp:291
#6 0x000000010003a7c9 in GLOBAL__I_a at /Users/alexanderstigsen/Documents/Dev/tightdb/test/testarray.cpp:1147
#7 0x00007fff5fc0fda6 in ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) ()
#8 0x00007fff5fc0faf2 in ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) ()
#9 0x00007fff5fc0d2e4 in ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) ()
#10 0x00007fff5fc0e0b7 in ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) ()
#11 0x00007fff5fc034dd in dyld::initializeMainExecutable() ()
#12 0x00007fff5fc0760b in dyld::main(macho_header const, unsigned long, int, char const
, char const
_, char const_*) ()
#13 0x00007fff5fc01059 in _dyld_start ()

Seems like a linking problem.

…was recently eliminated due to problem reports from Valgrind. The problem with not using function local statics, is that the order ot initialization of regular globals is undefined by the C++ standard.
@kspangsege
Copy link
Contributor Author

Problem fixed:

https://github.com/kspangsege/tightdb/commit/62b712fa7353511fb8da0d9ee62393bed6010454

On Tue, Aug 27, 2013 at 11:42 PM, astigsen notifications@github.com wrote:

Does not build on Xcode. File 'thread.cpp' is only member of 'libtightdb
ios' and not 'libtightdb'. So you get errors from the linker for missing
symbols.

Fixing that makes it build, but when trying to run the unit tests, it
crashes on startup.

Call stack:

#0 0x000000010022d475 in
tightdb::Array::create_empty_array(tightdb::Array::Type,
tightdb::Array::WidthType, tightdb::Allocator&) at
/Users/alexanderstigsen/Documents/Dev/tightdb/src/tightdb/array.cpp:1206
#1 #1 0x00000001004748e2 in
tightdb::Array::create_empty_array(tightdb::Array::Type,
tightdb::Allocator&) at
/Users/alexanderstigsen/Documents/Dev/tightdb/src/tightdb/array.hpp:1576
#2 #2 0x000000010040c248 in
tightdb::Array::create(tightdb::Array::Type) at
/Users/alexanderstigsen/Documents/Dev/tightdb/src/tightdb/array.hpp:1068
#3 #3 0x000000010047487c in
tightdb::Array::Array(tightdb::Array::Type, tightdb::ArrayParent_, unsigned
long, tightdb::Allocator&) at
/Users/alexanderstigsen/Documents/Dev/tightdb/src/tightdb/array.hpp:1014
#4 #4 0x000000010040c323 in
tightdb::Array::Array(tightdb::Array::Type, tightdb::ArrayParent_, unsigned
long, tightdb::Allocator&) at
/Users/alexanderstigsen/Documents/Dev/tightdb/src/tightdb/array.hpp:1016
#5 #5 0x0000000100038dbe in cxx_global_var_init
at /Users/alexanderstigsen/Documents/Dev/tightdb/test/testarray.cpp:291
#6 #6 0x000000010003a7c9 in
GLOBAL_I_a at
/Users/alexanderstigsen/Documents/Dev/tightdb/test/testarray.cpp:1147
#7 #7 0x00007fff5fc0fda6 in
ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) ()
#8 #8 0x00007fff5fc0faf2 in
ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) ()
#9 #9 0x00007fff5fc0d2e4 in
ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&,
unsigned int, ImageLoader::InitializerTimingList&) ()
#10 #10 0x00007fff5fc0e0b7 in
ImageLoader::runInitializers(ImageLoader::LinkContext const&,
ImageLoader::InitializerTimingList&) ()
#11 #11 0x00007fff5fc034dd in
dyld::initializeMainExecutable() ()
#12 #12 0x00007fff5fc0760b in
dyld::main(macho_header const, unsigned long, int, char const
, char
const__, char const_*) ()
#13 #13 0x00007fff5fc01059 in
_dyld_start ()

Seems like a linking problem.


Reply to this email directly or view it on GitHubhttps://github.com//pull/135#issuecomment-23373340
.

@astigsen
Copy link
Contributor

+1

BTW: Awesome that you included test results in the pull request. That should be done more often.

It would be nice in the future if big changes like that could be broken up in smaller pull requests. Then they could be reviewed faster and the whole process speeded up a bit.

kspangsege added a commit that referenced this pull request Aug 28, 2013
Bug fixes, documentation (source level), and general cleanup
@kspangsege kspangsege merged commit 6a3fda1 into realm:master Aug 28, 2013
@kspangsege kspangsege deleted the ks-cleanup branch August 28, 2013 09:42
@kspangsege
Copy link
Contributor Author

Finn, I a agree that the idiom would work, but I am reluctant towards introducing Pthread stuff outside the context of shared groups. It would be nice if one could take everything but SharedGroup and compile it on a platform without any threads support.

I think we should look a little further into the thread-safety of function local statics.

tgoyne pushed a commit that referenced this pull request Jul 11, 2018
Reduce number of threads used on Windows and Android
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants