Java Doc for LogAccessFile.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » impl » store » raw » log » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » db derby 10.2 » org.apache.derby.impl.store.raw.log 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.derby.impl.store.raw.log.LogAccessFile

LogAccessFile
public class LogAccessFile (Code)
Wraps a RandomAccessFile file to provide buffering on log writes. Only supports the write calls required for the log! MT - unsafe. Caller of this class must provide synchronization. The one exception is with the log file access, LogAccessFile will touch the log only inside synchronized block protected by the semaphore, which is defined by the creator of this object. Write to the log buffers are allowed when there are free buffers even when dirty buffers are being written(flushed) to the disk by a different thread. Only one flush writes to log file at a time, other wait for it to finish. Except for flushLogAccessFile , SyncAccessLogFile other function callers must provide syncronization that will allow only one of them to write to the buffers. Log Buffers are used in circular fashion, each buffer moves through following stages: freeBuffers --> dirtyBuffers --> freeBuffers. Movement of buffers from one stage to another stage is synchronized using the object(this) of this class. A Checksum log record that has the checksum value for the data that is being written to the disk is generated and written before the actual data. Except for the large log records that does not fit into a single buffer, checksum is calcualted for a group of log records that are in the buffer when buffers is switched. Checksum log record is written into the reserved space in the beginning buffer. In case of a large log record that does not fit into a bufffer, it needs to be written directly to the disk instead of going through the log buffers. In this case the log record write gets broken into three parts: 1) Write checksum log record and LOG RECORD HEADER (length + instant) 2) Write the log record. 3) Write the trailing length of the log record. Checksum log records helps in identifying the incomplete log disk writes during recovery. This is done by recalculating the checksum value for the data on the disk and comparing it to the the value stored in the checksum log record.


Field Summary
static  intmon_numBytesToLog
    
static  intmon_numWritesToLog
    

Constructor Summary
public  LogAccessFile(LogToFile logFactory, StorageRandomAccessFile log, int bufferSize)
    

Method Summary
public  voidclose()
    
public  voidcorrupt()
     The database is being marked corrupted, get rid of file pointer without writing out anything more.
protected  voidflushDirtyBuffers()
     Write data from all dirty buffers into the log file.

A call for clients of LogAccessFile to insure that all privately buffered data has been writen to the file - so that reads on the file using one of the various scan classes will see all the data which has been writen to this point.

Note that this routine only "writes" the data to the file, this does not mean that the data has been synced to disk unless file was opened in WRITE SYNC mode(rws/rwd).

public  voidflushLogAccessFile()
    
protected  longreserveSpaceForChecksum(int length, long logFileNumber, long currentPosition)
     reserve the space for the checksum log record in the log file.
public  voidswitchLogBuffer()
     Appends the current Buffer to the dirty Buffer list and assigns a free buffer to be the currrent active buffer .
public  voidsyncLogAccessFile()
     Guarantee all writes up to the last call to flushLogAccessFile on disk.

A call for clients of LogAccessFile to insure that all data written up to the last call to flushLogAccessFile() are written to disk. This call will not return until those writes have hit disk.

Note that this routine may block waiting for I/O to complete so callers should limit the number of resource held locked while this operation is called.

public  voidwrite(int b)
    
public  voidwrite(byte b, int off, int len)
    
protected  voidwriteEndMarker(int marker)
    
public  voidwriteInt(int i)
    
public  voidwriteLogRecord(int length, long instant, byte[] data, int data_offset, byte[] optional_data, int optional_data_offset, int optional_data_length)
     Write a single log record to the stream.

For performance pass all parameters rather into a specialized routine rather than maintaining the writeInt, writeLong, and write interfaces that this class provides as a standard OutputStream.

public  voidwriteLong(long l)
    

Field Detail
mon_numBytesToLog
static int mon_numBytesToLog(Code)



mon_numWritesToLog
static int mon_numWritesToLog(Code)




Constructor Detail
LogAccessFile
public LogAccessFile(LogToFile logFactory, StorageRandomAccessFile log, int bufferSize)(Code)




Method Detail
close
public void close() throws IOException, StandardException(Code)



corrupt
public void corrupt() throws IOException(Code)
The database is being marked corrupted, get rid of file pointer without writing out anything more.



flushDirtyBuffers
protected void flushDirtyBuffers() throws IOException(Code)
Write data from all dirty buffers into the log file.

A call for clients of LogAccessFile to insure that all privately buffered data has been writen to the file - so that reads on the file using one of the various scan classes will see all the data which has been writen to this point.

Note that this routine only "writes" the data to the file, this does not mean that the data has been synced to disk unless file was opened in WRITE SYNC mode(rws/rwd). The only way to insure that is by calling is to call syncLogAccessFile() after this call in Non-WRITE sync mode(rw)

MT-Safe : parallel thereads can call this function, only one threads does the flush and the other threads waits for the one that is doing the flush to finish. Currently there are two possible threads that can call this function in parallel 1) A Thread that is doing the commit 2) A Thread that is writing to the log and log buffers are full or a log records does not fit in a buffer. (Log Buffers full(switchLogBuffer() or a log record size that is greater than logbuffer size has to be writtern through writeToLog call directlty) Note: writeToLog() is not synchronized on the semaphore that is used to do buffer management to allow writes to the free buffers when flush is in progress.




flushLogAccessFile
public void flushLogAccessFile() throws IOException, StandardException(Code)



reserveSpaceForChecksum
protected long reserveSpaceForChecksum(int length, long logFileNumber, long currentPosition) throws StandardException, IOException(Code)
reserve the space for the checksum log record in the log file.
Parameters:
  length - the length of the log record to be written
Parameters:
  logFileNumber - current log file number
Parameters:
  currentPosition - current position in the log file. the space that is needed to write a checksum log record.



switchLogBuffer
public void switchLogBuffer() throws IOException, StandardException(Code)
Appends the current Buffer to the dirty Buffer list and assigns a free buffer to be the currrent active buffer . Flushing of the buffer to disk is delayed if there is a free buffer available. dirty buffers will be flushed to the disk when flushDirtyBuffers() is invoked by a commit call or when no more free buffers are available.



syncLogAccessFile
public void syncLogAccessFile() throws IOException, StandardException(Code)
Guarantee all writes up to the last call to flushLogAccessFile on disk.

A call for clients of LogAccessFile to insure that all data written up to the last call to flushLogAccessFile() are written to disk. This call will not return until those writes have hit disk.

Note that this routine may block waiting for I/O to complete so callers should limit the number of resource held locked while this operation is called. It is expected that the caller Note that this routine only "writes" the data to the file, this does not mean that the data has been synced to disk. The only way to insure that is to first call switchLogBuffer() and then follow by a call of sync().




write
public void write(int b)(Code)



write
public void write(byte b, int off, int len)(Code)



writeEndMarker
protected void writeEndMarker(int marker) throws IOException, StandardException(Code)



writeInt
public void writeInt(int i)(Code)



writeLogRecord
public void writeLogRecord(int length, long instant, byte[] data, int data_offset, byte[] optional_data, int optional_data_offset, int optional_data_length) throws StandardException, IOException(Code)
Write a single log record to the stream.

For performance pass all parameters rather into a specialized routine rather than maintaining the writeInt, writeLong, and write interfaces that this class provides as a standard OutputStream. It will make it harder to use other OutputStream implementations, but makes for less function calls and allows optimizations knowing when to switch buffers.

This routine handles all log records which are smaller than one log buffer. If a log record is bigger than a log buffer it calls writeUnbufferedLogRecord().

The log record written will always look the same as if the following code had been executed: writeInt(length) writeLong(instant) write(data, data_offset, (length - optional_data_length) ) if (optional_data_length != 0) write(optional_data, optional_data_offset, optional_data_length) writeInt(length)
Parameters:
  length - (data + optional_data) length bytes to write
Parameters:
  instant - the log address of this log record.
Parameters:
  data - "from" array to copy "data" portion of rec
Parameters:
  data_offset - offset in "data" to start copying from.
Parameters:
  optional_data - "from" array to copy "optional data" from
Parameters:
  optional_data_offset - offset in "optional_data" to start copy from
Parameters:
  optional_data_length - length of optional data to copy.
exception:
  StandardException - Standard exception policy.




writeLong
public void writeLong(long l)(Code)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

w___ww__.j_a___v_a___2___s___.c___o___m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.