Skip to content

Conversation

@coryan
Copy link
Contributor

@coryan coryan commented Dec 19, 2017

This is another PR in the series to fix #79. It implements the CreateTable() function.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Dec 19, 2017
@coryan coryan requested review from garye and mbrukman December 19, 2017 20:50
break;
}
if (not rpc_policy->on_failure(status)) {
throw std::runtime_error("could not create table");
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't tell me which table it had trouble creating.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

EXPECT_THROW(tested.ListTables(btproto::Table::FULL), std::exception);
}

/// @test Verify that bigtable::TableAdmin::Create works in the easy case.
Copy link
Contributor

Choose a reason for hiding this comment

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

bigtable::TableAdmin::Create() <-- code font + () ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

initial_splits { key: 'p' }
)""";
btproto::CreateTableRequest expected;
EXPECT_TRUE(google::protobuf::TextFormat::ParseFromString(expected_text,
Copy link
Contributor

Choose a reason for hiding this comment

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

ASSERT_TRUE? If it can't parse it, might as well fail now. Similarly elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

std::string delta;
google::protobuf::util::MessageDifferencer differencer;
differencer.ReportDifferencesToString(&delta);
EXPECT_TRUE(differencer.Compare(expected, request)) << delta;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the only thing we have for protobuf comparisons? There's no ASSERT_THAT gMock matcher support?

I couldn't find it; just asking if you know of anything that's more readable than MessageDifferencer.

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 did look too, could not find anything in googletest, nor in protobuf. At least the output is readable with the MessageDifferencer, though yes, the test code is less than awesome.

auto delay = backoff_policy->on_completion(status);
std::this_thread::sleep_for(delay);
}
return response;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bit unfortunate that we're returning a Table and not something like StatusOr, so we cannot propagate the error gracefully to the caller, just print it out to stderr.

Should we consider an exception-free implementation which returns the error as a Status? Or can that be the default implementation, and the exception version converts Status to an exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created #119 for this. We can create our own exception that derives from std::exception and encapsulates the grpc::Status.

::google::bigtable::admin::v2::Table TableAdmin::CreateTable(
std::string table_id, std::map<std::string, GcRule> column_families,
std::vector<std::string> splits,
::google::bigtable::admin::v2::Table::TimestampGranularity granularity) {
Copy link

Choose a reason for hiding this comment

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

We only support millisecond granularity right now. At the very least we should document this, or perhaps not expose it at all.

Copy link

Choose a reason for hiding this comment

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

Also, thoughts on creating a TableConfig or similar structure to make it easier to add new table params in the future?

Copy link
Contributor Author

@coryan coryan Dec 19, 2017

Choose a reason for hiding this comment

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

I think we should expose the API to set the granularity because if we don't then when we do it is a backwards incompatible change that would require a new major version number. Though maybe it would require that anyway.

Not opposed to TableConfig and in this case probably makes sense, will update this PR tomorrow.

if (status.ok()) {
break;
}
if (not rpc_policy->on_failure(status)) {
Copy link

Choose a reason for hiding this comment

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

What happens if the original requests succeeds but a transient error is returned, followed by an ALREADY_EXISTS error? Probably should not throw an exception.

Copy link
Contributor Author

@coryan coryan Dec 19, 2017

Choose a reason for hiding this comment

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

Hmm... there is a certain amount of ad-hoc logic that would be needed. We would need to query the table to return something meaningful. Created #121 for it because we will need to implement GetTable() to fix this. And that is coming in a future PR already.

granularity_(TIMESTAMP_GRANULARITY_UNSPECIFIED) {}

/// Move the contents to the proto to create tables.
void MoveTo(::google::bigtable::admin::v2::CreateTableRequest& request);
Copy link
Contributor

Choose a reason for hiding this comment

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

Google C++ style guide suggests (recommends?) using pointers for output params.

config.set_timestamp_granularity(bigtable::TableConfig::MILLIS);

auto const& families = config.column_families();
ASSERT_NE(families.end(), families.find("fam"));
Copy link
Contributor

Choose a reason for hiding this comment

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

What about:

auto it = families.find("fam");
ASSERT_NE(families.end(), it);
EXPECT_EQ(2, it->second...);

Copy link
Contributor

@mbrukman mbrukman left a comment

Choose a reason for hiding this comment

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

LGTM

All my concerns have been addressed (thanks!); over to @garye for approval.

@mbrukman
Copy link
Contributor

@coryan — looks like builds are failing:

.../bigtable/admin/table_admin_test.cc:27:45: fatal error: bigtable/client/chrono_literals.h: No such file or directory
 #include "bigtable/client/chrono_literals.h"
                                             ^

Was this file moved to bigtable/client/test/* in this or another PR? I feel like I've seen that in one of the dozen PRs I reviewed recently. 😄

@coryan coryan force-pushed the minimal-admin-client-t3 branch from 5498d64 to b06abe1 Compare December 21, 2017 01:45
@coryan coryan merged commit 255497c into googleapis:master Dec 21, 2017
@coryan coryan deleted the minimal-admin-client-t3 branch December 21, 2017 02:54
@coryan
Copy link
Contributor Author

coryan commented Dec 21, 2017

Needed to rebase and then fix a path. It was hilarious to get a clean merge that broken all the builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a client library for the Admin API.

4 participants