birth, death, infinity - PUG Challenge Americas

Download Report

Transcript birth, death, infinity - PUG Challenge Americas

Birth, Death, Infinity
Gus Björklund. Progress.
Dan Foreman. BravePoint.
PUG Challenge Americas, 9-12 June 2013
who are we ?
3
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Conception
5
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
A Table is defined
Methods for defining a new table:
 Use the Data Dictionary Tool
• Type in all the information
 Load a "df" file
•
run prodict/load_df.p (os-getenv ("SCHEMADIR") + "/"
"customer.df").
 Execute a SQL DDL statement
• CREATE TABLE pub.customer (cust-num integer, . . . ) AREA "a51";
6
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Where does the definition go?
Table definitions
_file
_field
_field
_field
_field
_field
One _field record (row) for each field (column) of a table
The _* tables live in the Schema Area. Put yours elsewhere.
8
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
List Your Tables and Their Fields
output to tables.txt.
for each _file
where (0 < _file-num):
put _file-name skip.
for each _field of _file:
put “
“ _field-name skip.
end.
put “” skip.
end.
output close.
9
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Index definitions
_file
_index
_index-field
_index
_index-field
_index-field
_index-field
One _index record for each index of a table
One _index-field record for each key
component of an index
10
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
List indexes and key components by table
output to index.txt.
for each _file where (0 < _file-num):
put _file-name skip.
for each _index of _file:
put "
" _index-name skip.
for each _index-field of _index:
find _field
where recid (_field) = _field-recid.
put "
" _field-name skip.
end.
end.
put "" skip.
end.
output close.
11
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Where do the default values go?
the template record
 Each table has a template record
 Column values in the template become the default values
 Template records NOT stored with schema metadata
• go in table's home area or schema area (v11)
• have to read from database to get template
 TODAY and NOW defaults replaced with current values
13
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Birth
14
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
CREATE a new row in a 4GL program
create customer.
15
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
CREATE a new row in a 4GL program
create customer.
what happens?
we read template record from database
(if we don't have it already)
client buffer is filled with a copy of the template record
current values inserted for TODAY, NOW
no write to database – db knows nothing about the
create at this point.
16
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Where does customer row go?
CONDB
Etc.
order
DBDES
customer
ICB for table
customer
CI for
customer
17
FDTBL for
database foo
© 2013 Progress Software Corporation. All rights reserved.
row buffer
Birth, Death, Infinity
assign column values
Address
Address2
City
Contact
Curr-bal
Cust-num
Discount
Max-credit
Mnth-sales
Name
18
© 2013 Progress Software Corporation. All rights reserved.
Phone
Sales-region
Sales-rep
St
Tax-no
Terms
Ytd-sls
Zip
Birth, Death, Infinity
when do we send it to the database ?
database accelerator
20
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
send row to database
client's row buffer
client's network
message buffer
21
© 2013 Progress Software Corporation. All rights reserved.
server's row buffer
TCP/IP
server's network
message buffer
Birth, Death, Infinity
where do we put it ?
Database Pages (Blocks)





Database divided into fixed-size blocks or “pages”
Adjacent pages form clusters
Different kinds of pages store different kinds of data
Disk i/o done in page size units
Each page has unique identifier – its “dbkey”
see these slides for space allocation algorithm details
Space, the final frontier
http://communities.progress.com/pcom/docs/DOC-107729
23
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Find data block, read into database buffer pool
“newest”
M
M
Hash
Table
24
“oldest”
LRU Chain
M
M
M
M
Checkpoint Queue
© 2013 Progress Software Corporation. All rights reserved.
M
M
M
Page Writer Queue
Birth, Death, Infinity
Update data block







25
note: simplified.
acquire exclusive lock on buffer
generate "create" bi note
spool bi note
copy from row buffer to data block
update block free space if needed
mark buffer modified
release buffer lock
© 2013 Progress Software Corporation. All rights reserved.
some details
omitted to
protect the
innocent
Birth, Death, Infinity
Record In A Row Data Block (aka RM Block)
block header
RM block header
dir entry 0
dir entry 1
dir entry 2
dir entry 3
Newly created row is stored
in some row data block and
assigned an available
directory entry.
The chosen block and
directory entry determine the
ROWID
free space
record 3
record 2
record 1
record 0
26
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Birth Alternatives
27
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Other ways records are born
 sql:
INSERT INTO customer (cust-no, name street, city, state)
VALUES (642, 'gus', '14 oak park', 'bedford', 'ma');
 sql:
INSERT INTO customer (cust-no, name street, city, state)
SELECT . . . FROM . . . WHERE . . . ;
 binary load:
proutil foo -C load bar.bd
28
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Possible Problems
29
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Things to consider
 When record is sent to database before all the values are
assigned, one database operation
• create
 becomes several
• create
• update
• update
• etc.
 The record expands as more values are assigned
• fragmentation will occur
30
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Life
31
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
READ
find customer
where cust-num = 3447.
32
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
READ
 Compiler determines index to use (perhaps cust-num)
• R-code has index information
• Query used to form equality or range bracket












33
At runtime, load schema cache into memory
Look up the table number (# 3)
Find _storage-object records for table #3 (for tenant #t)
Look up the index number (# 113)
Find _storage-object records for index #113 (for tenant #t)
Load into “om cache” so we can use again (set -omsize)
Get location of index root block from _storage-object
Traverse index b-tree to leaf, perhaps cust-num = 3447
Get row's rowid 9006 from index leaf block
Get share lock on row 9006
Read data block(s) containing row fragments
Copy row fragments to 4GL buffer or network buffer
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Find row in database
Block’s DBKEY
Type
Next DBKEY in Chain
Num
Dirs.
Chain
Backup Ctr
Block Update Counter
Free
Dirs.
Rec 2 Offset
Free Space
Rec 0 Offset
Rec 1 Offset
Rec n Offset
Free Space
Share locked
RM block in
buffer pool
Used Data Space
Record 1
Record 2
Record 0
client's row buffer
server’s row buffer
server’s network
message buffer
34
© 2013 Progress Software Corporation. All rights reserved.
TCP/IP
client’s network
message buffer
Birth, Death, Infinity
row buffer connected
CONDB
Etc.
order
DBDES
customer
ICB for table
customer
CI for
customer
35
FDTBL for
database foo
© 2013 Progress Software Corporation. All rights reserved.
row buffer (cust 3447)
Birth, Death, Infinity
UPDATES
do transaction:
find customer
where cust-num = 3447 exclusive-lock:
customer.city = "Westford".
end.
end.
36
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Assign new value to city
4GL runtime stack
ICB for table customer
“Westford”
CI for customer
field n
Boston
row buffer (cust 3447)
37
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Assign new value to city
4GL runtime stack
ICB for table customer
“Westford”
CI for customer
field n
Westford
row buffer
38
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
when do we send it to the database ?
send row to database
client's row buffer
client's network
message buffer
40
© 2013 Progress Software Corporation. All rights reserved.
server's row buffer
TCP/IP
server's network
message buffer
Birth, Death, Infinity
Update data block
 Acquire exclusive lock block buffer
 read data block into buffer pool
 generate "record difference" bi note
 spool bi note
 modify data block
 update free space
 mark block modified
 release buffer lock
41
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Update other data blocks
 Indexes have to be updated too (city is a key field)
 delete existing index entry for "Boston"
 insert new index entry for "Westford"
42
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Fragment chain
block header
block header
RM block header
dir entry 0
dir entry 1
dir entry 2
dir entry 3
RM block header
dir entry 0
dir entry 1
free
space
record
3
(part 1 of row)
free space
record 2
record 1
record 0
43
© 2013 Progress Software Corporation. All rights reserved.
record 1 (part 2 of row)
record 0
Birth, Death, Infinity
Death
44
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Deleting
do transaction:
for each customer
where city = "Boston":
delete customer.
end.
end.
45
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Deleting (sql)
delete from customer where city = "Boston";
46
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Update data block
 Acquire exclusive lock block buffer
 read data block into buffer pool
 generate "record delete" bi note
 spool bi note
 modify data block
 update free space
 mark block modified
 release buffer lock
47
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Update other data blocks
 Indexes have to be updated too
 After each record delete
• delete existing index entry for "Boston"
• delete all the other index entries too
 For unique index entries, replace with a reservation (placeholder)
• the key value cannot be used until deleting transaction commits
48
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
deleted ROWID Reservation
block header
RM block header
dir entry 0
dir entry 1
dir entry 2
dir entry 3
ROWID cannot be recycled
until after the deleting
transaction commits.
Why ?
free space
record 2
record 1
record 0
49
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
deleted ROWID Reservation
block header
RM block header
dir entry 0
dir entry 1
dir entry 2
dir entry 3
free space
ROWID cannot be recycled
until after the deleting
transaction commits.
Why ?
What ELSE can go wrong
during UNDO ?
record 2
record 1
record 0
50
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
What could go wrong ?
deleted ROWID Reservation
block header
RM block header
dir entry 0
dir entry 1
dir entry 2
dir entry 3
free space
ROWID cannot be recycled
until after the deleting
transaction commits.
Why ?
What ELSE can go wrong
during UNDO ?
record 2
record 1
record 0
52
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
deleted ROWID Reservation
block header
RM block header
dir entry 0
dir entry 1
dir entry 2
dir entry 3
free space
record 2
ROWID cannot be recycled
until after the deleting
transaction commits.
Why ?
What can go wrong during
UNDO ?
Not enough space. another
transaction has taken it.
record 1
record 0
53
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Infinity
How can a row live after death ?
Life after death
 Your records live on forever in:
• Backup archives
• Archived after-image extents
• Audit data
• Archived audit data
• Binary dump files
• Reports
• Dropbox
• etc.
 If you have any of these, where? Can you find a specific record?
 Are the data encrypted? Where are the keys ?
 Can we subpeona your records ? We may.
56
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
That’s all we have time for
today, except
57
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity
Answers
email:
[email protected]
[email protected]
58
© 2013 Progress Software Corporation. All rights reserved.
Birth, Death, Infinity