Skip to content

Commit a2d2d8c

Browse files
author
Joseph Lowinske
committed
resolve merge conflicts
2 parents fbefd60 + 5ad2c23 commit a2d2d8c

File tree

1,370 files changed

+15144
-3457
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,370 files changed

+15144
-3457
lines changed

CONTRIBUTING.md

+2-2

_includes/expand.html

-46
This file was deleted.

_includes/sidebar-data-v2.0.json

+6
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,12 @@
11541154
}
11551155
]
11561156
},
1157+
{
1158+
"title": "Performance Benchmarking with TPC-C",
1159+
"urls": [
1160+
"/${VERSION}/performance-benchmarking-with-tpc-c.html"
1161+
]
1162+
},
11571163
{
11581164
"title": "Access Management",
11591165
"items": [

_includes/sidebar-data-v2.1.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@
282282
}
283283
]
284284
},
285+
{
286+
"title": "Performance Benchmarking with TPC-C",
287+
"urls": [
288+
"/${VERSION}/performance-benchmarking-with-tpc-c.html"
289+
]
290+
},
285291
{
286292
"title": "Access Management",
287293
"items": [
@@ -328,7 +334,7 @@
328334
},
329335
{
330336
"title": "Encryption at Rest",
331-
"ursl": [
337+
"urls": [
332338
"/${VERSION}/encryption.html"
333339
]
334340
},

_includes/topnav.html

+27-27
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@
2828
<span class="blue-arrow blue-arrow--down"></span>
2929
Resources
3030
<div class="mobile-sub-nav">
31-
<a href="https://www.cockroachlabs.com/guides/">Guides</a>
32-
<a href="https://www.cockroachlabs.com/docs/stable/training">Training</a>
33-
<a href="https://www.cockroachlabs.com/community/tech-talks/">Tech Talks</a>
34-
<a href="https://forum.cockroachlabs.com/">Forum</a>
31+
<span>Spotlights</span>
32+
<ul class="mobile-sub-nav--link-list">
33+
<li><a href="https://www.cockroachlabs.com/campaigns/kubernetes/">How to Run CockroachDB on Kubernetes</a></li>
34+
</ul>
35+
<a href="https://www.cockroachlabs.com/guides/">Guides</a>
36+
<a href="https://www.cockroachlabs.com/docs/stable/training/">Training</a>
37+
<a href="https://forum.cockroachlabs.com/">Forum</a>
3538
</div>
3639
</div>
3740
<a href="https://www.cockroachlabs.com/blog/" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-depth-0">Blog</a>
@@ -41,26 +44,26 @@
4144
<header class="navbar-fixed-top">
4245
<div class="navbar-fixed-top--inner">
4346
<a class="logo" href="https://www.cockroachlabs.com/" title="Cockroach Labs">
44-
<img src="{{ 'images/CL_Logo_Horizontal.svg' | relative_url }}" width="100%" alt="Cockroach Labs" />
47+
<img src="{{ 'images/CL_Logo_Horizontal.svg' | relative_url }}" width="100%" alt="Cockroach Labs" />
4548
</a>
46-
49+
4750
<nav class="desktop" role="navigation">
4851
<div class='menu-item-dropdown'>
4952
Product
5053
<div class="menu-dropdown">
51-
<a href="/product/cockroachdb/" data-proofer-ignore>
54+
<a href="https://www.cockroachlabs.com/product/cockroachdb/" data-proofer-ignore>
5255
<div class="menu-dropdown__title">CockroachDB</div>
5356
<div class="menu-dropdown__info">The SQL database for global cloud services.</div>
5457
</a>
55-
<a href="/solutions/automated-operation/" data-proofer-ignore>
58+
<a href="https://www.cockroachlabs.com/solutions/automated-operation/" data-proofer-ignore>
5659
<div class="menu-dropdown__title">Automated Operation</div>
5760
<div class="menu-dropdown__info">Automate tasks like scaling, replication, and recovery.</div>
5861
</a>
59-
<a href="/solutions/global-clusters/" data-proofer-ignore>
62+
<a href="https://www.cockroachlabs.com/solutions/global-clusters/" data-proofer-ignore>
6063
<div class="menu-dropdown__title">Global Clusters</div>
6164
<div class="menu-dropdown__info">Scale your infrastructure across datacenters and regions.</div>
6265
</a>
63-
<a href="/pricing/" data-proofer-ignore>
66+
<a href="https://www.cockroachlabs.com/pricing/" data-proofer-ignore>
6467
<div class="menu-dropdown__title">Pricing</div>
6568
</a>
6669
<a href="{{ "/stable/frequently-asked-questions.html" | relative_url }}" data-proofer-ignore>
@@ -73,23 +76,20 @@
7376
<div class='menu-item-dropdown'>
7477
<div class="menu-item-dropdown__parent-link">Resources</div>
7578
<div class="menu-dropdown">
76-
<a href="https://www.cockroachlabs.com/guides/" data-proofer-ignore>
77-
<div class="menu-dropdown__title">Guides</div>
78-
<div class="menu-dropdown__info">Comprehensive guides about distributed technology.</div>
79-
</a>
80-
<a href="https://www.cockroachlabs.com/docs/stable/training" data-proofer-ignore>
81-
<div class="menu-dropdown__title">Training</div>
82-
<div class="menu-dropdown__info">E-learnings on CockroachDB fundamentals.</div>
83-
</a>
84-
<a href="https://www.cockroachlabs.com/community/tech-talks/" data-proofer-ignore>
85-
<div class="menu-dropdown__title">Tech Talks</div>
86-
<div class="menu-dropdown__info">Videos and slides explaining how CockroachDB works.</div>
87-
</a>
88-
<a href="https://forum.cockroachlabs.com/" data-proofer-ignore>
89-
<div class="menu-dropdown__title">Forum</div>
90-
<div class="menu-dropdown__info">Need help? Ask questions on the developer forum.</div>
91-
</a>
92-
</div>
79+
<div class="menu-dropdown--subsection">
80+
<span class="menu-dropdown--subsection__title">Spotlights</span>
81+
<a class="menu-dropdown--subsection__link" href="https://www.cockroachlabs.com/campaigns/kubernetes/">How to Run CockroachDB on Kubernetes</a>
82+
</div>
83+
<a href="https://www.cockroachlabs.com/guides/">
84+
<div class="menu-dropdown__title">Guides</div>
85+
</a>
86+
<a href="https://www.cockroachlabs.com/docs/stable/training/" data-proofer-ignore>
87+
<div class="menu-dropdown__title">Training</div>
88+
</a>
89+
<a href="https://forum.cockroachlabs.com/">
90+
<div class="menu-dropdown__title">Forum</div>
91+
</a>
92+
</div>
9393
</div>
9494
<a href="https://www.cockroachlabs.com/blog/" class='blog-nav' data-proofer-ignore>Blog</a>
9595
<a href="{{ "/stable/install-cockroachdb.html" | relative_url }}" class="button--header menu-item" data-proofer-ignore>Download</a>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

_includes/faq/sql-query-logging.md renamed to _includes/v1.0/faq/sql-query-logging.md

+1-1

_includes/v1.1/app/BasicSample.java

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import java.sql.*;
2+
3+
/*
4+
You can compile and run this example with a command like:
5+
javac BasicSample.java && java -cp .:~/path/to/postgresql-9.4.1208.jar BasicSample
6+
You can download the postgres JDBC driver jar from https://jdbc.postgresql.org.
7+
*/
8+
public class BasicSample {
9+
public static void main(String[] args) throws ClassNotFoundException, SQLException {
10+
// Load the postgres JDBC driver.
11+
Class.forName("org.postgresql.Driver");
12+
13+
// Connect to the "bank" database.
14+
Connection db = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:26257/bank?sslmode=disable", "maxroach", "");
15+
16+
try {
17+
// Create the "accounts" table.
18+
db.createStatement().execute("CREATE TABLE IF NOT EXISTS accounts (id INT PRIMARY KEY, balance INT)");
19+
20+
// Insert two rows into the "accounts" table.
21+
db.createStatement().execute("INSERT INTO accounts (id, balance) VALUES (1, 1000), (2, 250)");
22+
23+
// Print out the balances.
24+
System.out.println("Initial balances:");
25+
ResultSet res = db.createStatement().executeQuery("SELECT id, balance FROM accounts");
26+
while (res.next()) {
27+
System.out.printf("\taccount %s: %s\n", res.getInt("id"), res.getInt("balance"));
28+
}
29+
} finally {
30+
// Close the database connection.
31+
db.close();
32+
}
33+
}
34+
}

_includes/v1.1/app/TxnSample.java

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import java.sql.*;
2+
3+
/*
4+
You can compile and run this example with a command like:
5+
javac TxnSample.java && java -cp .:~/path/to/postgresql-9.4.1208.jar TxnSample
6+
You can download the postgres JDBC driver jar from https://jdbc.postgresql.org.
7+
*/
8+
9+
// Ambiguous whether the transaction committed or not.
10+
class AmbiguousCommitException extends SQLException{
11+
public AmbiguousCommitException(Throwable cause) {
12+
super(cause);
13+
}
14+
}
15+
class InsufficientBalanceException extends Exception {}
16+
class AccountNotFoundException extends Exception {
17+
public int account;
18+
public AccountNotFoundException(int account) {
19+
this.account = account;
20+
}
21+
}
22+
23+
// A simple interface that provides a retryable lambda expression.
24+
interface RetryableTransaction {
25+
public void run(Connection conn)
26+
throws SQLException, InsufficientBalanceException, AccountNotFoundException, AmbiguousCommitException;
27+
}
28+
29+
public class TxnSample {
30+
public static RetryableTransaction transferFunds(int from, int to, int amount) {
31+
return new RetryableTransaction() {
32+
public void run(Connection conn)
33+
throws SQLException, InsufficientBalanceException, AccountNotFoundException, AmbiguousCommitException {
34+
// Check the current balance.
35+
ResultSet res = conn.createStatement().executeQuery("SELECT balance FROM accounts WHERE id = " + from);
36+
if(!res.next()) {
37+
throw new AccountNotFoundException(from);
38+
}
39+
int balance = res.getInt("balance");
40+
if(balance < from) {
41+
throw new InsufficientBalanceException();
42+
}
43+
// Perform the transfer.
44+
conn.createStatement().executeUpdate("UPDATE accounts SET balance = balance - " + amount + " where id = " + from);
45+
conn.createStatement().executeUpdate("UPDATE accounts SET balance = balance + " + amount + " where id = " + to);
46+
}
47+
};
48+
}
49+
50+
public static void retryTransaction(Connection conn, RetryableTransaction tx)
51+
throws SQLException, InsufficientBalanceException, AccountNotFoundException, AmbiguousCommitException {
52+
Savepoint sp = conn.setSavepoint("cockroach_restart");
53+
while(true) {
54+
boolean releaseAttempted = false;
55+
try {
56+
tx.run(conn);
57+
releaseAttempted = true;
58+
conn.releaseSavepoint(sp);
59+
}
60+
catch(SQLException e) {
61+
String sqlState = e.getSQLState();
62+
// Check if the error code indicates a SERIALIZATION_FAILURE.
63+
if(sqlState.equals("40001")) {
64+
// Signal the database that we will attempt a retry.
65+
conn.rollback(sp);
66+
continue;
67+
} else if(releaseAttempted) {
68+
throw new AmbiguousCommitException(e);
69+
} else {
70+
throw e;
71+
}
72+
}
73+
break;
74+
}
75+
conn.commit();
76+
}
77+
78+
public static void main(String[] args) throws ClassNotFoundException, SQLException {
79+
// Load the postgres JDBC driver.
80+
Class.forName("org.postgresql.Driver");
81+
82+
// Connect to the "bank" database.
83+
Connection db = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:26257/bank?sslmode=disable", "maxroach", "");
84+
try {
85+
// We need to turn off autocommit mode to allow for
86+
// multi-statement transactions.
87+
db.setAutoCommit(false);
88+
// Perform the transfer. This assumes the table has
89+
// already been set up as in the "Build a Test App"
90+
// tutorial.
91+
RetryableTransaction transfer = transferFunds(1, 2, 100);
92+
retryTransaction(db, transfer);
93+
94+
// Check balances after transfer.
95+
db.setAutoCommit(true);
96+
ResultSet res = db.createStatement().executeQuery("SELECT id, balance FROM accounts");
97+
while (res.next()) {
98+
System.out.printf("\taccount %s: %s\n", res.getInt("id"), res.getInt("balance"));
99+
}
100+
} catch(InsufficientBalanceException e) {
101+
System.out.println("Insufficient balance");
102+
} catch(AccountNotFoundException e) {
103+
System.out.println("No users in the table with id " + e.account);
104+
} catch(AmbiguousCommitException e) {
105+
System.out.println("Ambiguous result encountered: " + e);
106+
} catch(SQLException e) {
107+
System.out.println("SQLException encountered:" + e);
108+
} finally {
109+
// Close the database connection.
110+
db.close();
111+
}
112+
}
113+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
require 'active_record'
2+
require 'pg'
3+
require 'activerecord-cockroachdb-adapter'
4+
5+
# Connect to CockroachDB through ActiveRecord.
6+
# In Rails, this configuration would go in config/database.yml as usual.
7+
ActiveRecord::Base.establish_connection(
8+
adapter: 'cockroachdb',
9+
username: 'maxroach',
10+
password: '',
11+
database: 'bank',
12+
host: 'localhost',
13+
port: 26257,
14+
)
15+
16+
17+
# Define the Account model.
18+
# In Rails, this would go in app/models/ as usual.
19+
class Account < ActiveRecord::Base
20+
validates :id, presence: true
21+
validates :balance, presence: true
22+
end
23+
24+
# Define a migration for the accounts table.
25+
# In Rails, this would go in db/migrate/ as usual.
26+
class Schema < ActiveRecord::Migration
27+
def change
28+
create_table :accounts, force: true do |t|
29+
t.integer :balance
30+
end
31+
end
32+
end
33+
34+
# Run the schema migration by hand.
35+
# In Rails, this would be done via rake db:migrate as usual.
36+
Schema.new.change()
37+
38+
# Create two accounts, inserting two rows into the accounts table.
39+
Account.create(id: 1, balance: 1000)
40+
Account.create(id: 2, balance: 250)
41+
42+
# Retrieve accounts and print out the balances
43+
Account.all.each do |acct|
44+
puts "#{acct.id} #{acct.balance}"
45+
end

0 commit comments

Comments
 (0)