Pages

Wednesday, December 28, 2011

Java 7 Concurrency


Improvements and new concurrency features have been added to Java 7 as part of the JSR 166Y. This topic is part of the Oracle Certified Professional (OCP) Java 7 Certification exam and is a primary objective for the 1Z0-805 Java 7 Upgrade Exam (Beta version was 1Z1-805).

1. Identify potential threading problems


2. Use java.util.concurrent collections

Following have been updated in Java 7:
ForkJoinPool, Phaser, TransferQueue, ConcurrentLinkedDeque, ThreadLocalRandom - provides better performance with less contention than Math.random. e.g. ThreadLocalRandom.current().nextInt(0,100)


3. Use atomic variables and locks

Atomic variables can be defined using atomic types in java.util.concurrent.atomic package. Using atomic variable ensures that operations on that variable are thread safe and no block/method synchronization is required. Examples, AtomicInteger, AtomicLongArray

Instead of synchronized code, Java 7 provides more efficient java.util.concurrent.locks package.


4. Executors and ThreadPools

There are 3 executor interfaces in java.util.concurrent:
  • Executor - to launch new tasks
    Using Executor, (new Thread(runnable)).start() can be written as executor.execute(runnable)
    Instead of starting a new thread, an existing thread may be used from the ThreadPool, thus optimizing performance.
  • ExecutorService - subinterface of Executor to manage the executor and the service
  • ScheduledExecutorService - subinterface of ExecutorService to manage schedule tasks
ThreadPool is a commonly used implementation of the Executor.

5. Use the parallel Fork/Join framework

New framework in Java 7 to take advantage of multiple processors on a machine.

Tuesday, December 27, 2011

Java 7 NIO.2



Java File I/O (NIO.2) is part of the Oracle Certified Professional (OCP) Java 7 Certification exam.

The basic classes to focus in java.nio.file are:

The 1Z0-805 upgrade exam (Beta exam was 1Z1-805) objectives for NIO.2 are:

1. Use the Path class to operate on file and directory paths

Path object can be created using Paths.get(...) or FileSystem.getPath(...). FileSystem object can be created from FileSystems.

Path has methods to operate on the path: getFileName(), getName(idx), getNameCount(), getParent(), getRoot(), hashCode(), isAbsolute(), iterator(), normalize(), subpath(begin,end), toFile() - returns java.io.File, toString()

Path has methods to operate based on another given Path/String: startsWith, endsWith, relativize, resolve, resolveSibling, comparesTo

Path has 3 ways to convert a path toAbsolutePath(),  toUri(), toRealPath(Link Option). toRealPath(...) returns an absolute path after resolving redundancies and if argument is true then resolving symbolic links as well.

register method can be used to register a Path for a WatchService and returns a WatchKey.


Exam Watch:
  • Path is system dependent. Path on Windows and Linux with same directory structure will be different.
  • Path representing file/dir may not exist
  • Path can be operated on to append, extract pieces, duplicate, or compare, but java.nio.file.File has to be used on the Path for actual file operations

2. Use the Files class to check, delete, copy, or move a file or directory

Files class has a set of static methods to work on a file/dir. Methods in Files are symbolic link aware. 

Simple example to create file using NIO.2:
Charset charset = Charset.forName("US-ASCII");
String str = "test";
try (BufferedWriter writer = Files.newBufferedWriter(myFile, charset)) {
    writer.write(str, 0, str.length());
} catch (IOException ioe) {
    System.err.format("IOException: %s%n", ioe);
}
 
File I/O Methods complexity diagram: 

[Ref: Java Tutorials, oracle.com]

Check
Check file: Files.exists(Path, LINK_OPTIONS...), Files.notExists(Path, LINK_OPTIONS...)
If both return false then existence can not be determined - possible when access permission is denied


Check if 2 Paths point to same file: Files.isSameFile(Path, Path)


Delete
Files.delete(Path) may throw NoSuchFileException, DirectoryNotEmptyException, or else for permission problems - IOException. 

ExamWatch:
Files.deleteIfExists(Path) will never throw NoSuchFileException 

Copy
syntax:    Files.copy(Path, Path, COPY_OPTIONS...);example: Files.copy( src, target, REPLACE_EXISTING, NOFOLLOW_LINKS);

COPY_OPTIONS (Requires import static java.nio.file.StandardCopyOption.*;):
  • REPLACE_EXISTING - will replace existing file or symbolic link (not target of link) and empty directory. If target is existing non empty directory then FileAlreadyExistsException is thrown.
  • COPY_ATTRIBUTES - will copy file attributes including file's last modified time
  • NOFOLLOW_LINKS - when specified, the symbolic link will be copied and not the target of the link
Similarly, Files.copy(InputStream, Path, COPY_OPTION) and Files.copy(Path, OutputStream) can be used.

Move
syntax:    Files.move(Path, Path, MOVE_OPTIONS...);
example: Files.move( src, target, REPLACE_EXISTING, ATOMIC_MOVE);

MOVE_OPTIONS (Requires import static java.nio.file.StandardCopyOption.*;):
  • REPLACE_EXISTING
  • ATOMIC_MOVE - exception is thrown if filesystem does not support atomic move

Some specific exceptions extend FileSystemException that has useful methods - getFile(), getMessage(), getReason(), getOtherFile() if any other file was involved.

 

3. Read and change file and directory attributes

Check accessibility with Files: isReadable(Path), isWritable(Path), isExecutable(Path)
Also available in Files:
For bulk operations, String or Class<A> parameter can identify the attributes to be read in one operation using:
Files.readAttributes(Path, String, LinkOption...) or Files.readAttributes(Path, Class<A>, LinkOption...)

PredefinedViews:  
BasicFileAttributeView, DosFileAttributeView, PosixFileAttributeView, FileOwnerAttributeView, AclFileAttributeView , UserDefinedFileAttributeView – Enables support of metadata that is user defined.
 
4. Recursively access a directory tree

Create a  FileVisitor. Then, either of the following can be used:

 

5. Find a file by using the PathMatcher class

For FileSystem syntax can be "glob" or "regex"

String pattern = ...;
PathMatcher matcher = FileSystems.getDefault().getPathMatcher(syntax + ":" + pattern);
 
glob:
*   0 or more char, but does not cross directory. Will match .<file> 
**  0 or more char crossing directories
?   single character of name
[]  single character or a range. Within [], *?\ will match itself.
{}  comma separated subpatterns
 \      escape for special characters


6. Watch a directory for changes by using WatchService

Steps to create a WatchService:
  • Create "watcher",  a WatchService for the file system.
    WatchService watcher = FileSystems.getDefault().newWatchService();
  • Register each dir to be watched with the watcher. When registering specify the type of events for notification. A WatchKey instance is received for each registered directory.
    Path dir = ...;
    WatchKey key = dir.register(watcher, ENTRY_DELETE, ENTRY_MODIFY);
  • Implement an infinite loop to wait for incoming events. When an event occurs, the key is signaled and placed into the watcher's queue.
  • Retrieve the key from the watcher's queue and obtain the file name from the key.
    WatchService provides poll(), poll(long, TimeUnit), take() to get a signalled key. 
  • Retrieve each pending event using key.pollEvents() and process using event.kind().
    event.context() returns the file name.
  • Reset the key by calling key.reset(). If true resume waiting for events, else break.
  • Close the service: The watch service exits when either the thread exits or when it is closed by calling watcher.close().



[Ref] Java Tutorials on File I/O featuring NIO.2

Java 7 launch video on NIO.2 from Oracle Media Network:






Java 7 Language Enhancements

This topic is part of OCP Java 7 Upgrade Exam - 1Z0-805 (Beta exam was 1Z1-805) Objective 1.


Language Enhancements [JSR 334]

Language enhancements were made as part of Project Coin.

1. String in the switch statement

Java 7 allows String object in switch statement and consequently String literals or final String constants in case. String.equals is used to match the case, hence matching is case sensitive.
[Ref]

2. Binary literals, numeric literals with underscores

Integral types - byte, short, int, and long - can be represented as binary numbers in Java 7. 
Examples: 0b010, 0B101
This representation is very similar to the hexadecimal representation using 0x. 
Using binary representation may be useful when dealing with bitmaps.
[Ref


It is sometimes difficult to read large numeric literals, requiring counting number of digits or zeros. With Java 7 enhancement, numbers like ten million and fifty thousand (10050000) can be represented as 10_050_000 to make it easier to read for humans.
[Ref]


3. try-with-resources

Instead of developer dealing with exceptions and closing appropriate resources in catch or finally block, Java 7 allows placing such resources within try parenthesis and automatically deals with closing such resources.
[Ref]
Sample:
try (
  Statement stmt = conn.createStatement();
  BufferedWriter bufw = new BufferedWriter(new FileWriter("foo.txt"));
) {
  ...
} catch(Exception e) {
  ...
}

4. Multi-catch in exception statements, 6. More precise rethrow in exceptions

Instead of catching each exception separately and handle them individually, Java 7 allows to catch and handle group of exceptions separated by "|" . Syntax is of the form:
catch (Exception1 | Exception2) {} 

Exam Watch:
  • If a catch block handles more than one exception type, then the catch parameter is implicitly final 
  • Bytecode generated by compiling a catch block that handles multiple exception types will be smaller (and thus superior) than compiling many catch blocks that handle only one exception type each. A catch block that handles multiple exception types creates no duplication in the bytecode generated by the compiler; the bytecode has no replication of exception handlers.



On rethrow, Java 7 is capable of determining the appropriate exception thrown based on the exceptions that a method throws. Example:


void method1() throws Exception1, Exception2 {
    try {
        ...
    } catch(Exception e) {
        throw e; // Java 7 can determine if Exception1 of 2 was throws here
    }
}


Exam Watch:
  • This analysis is disabled if the catch parameter is assigned to another value in the catch block.
  • If the catch parameter is assigned to another value, you must specify the exception type Exception in the throws clause of the method declaration.
  • When you declare one or more exception types in a catch clause, and rethrow the exception handled by this catch block, the compiler verifies that the type of the rethrown exception meets the following conditions:
    1. The try block is able to throw it.
    2. There are no other preceding catch blocks that can handle it.
    3. It is a subtype or supertype of one of the catch clause's exception parameters.
  • You can rethrow an exception that is a supertype of any of the types declared in the throws
[Ref]


5. The diamond operator with generic declarations

Java 7 allows using <> operator on the right side of a new construct, thereby simplifying generic declaration. Example:

List<String> names = new ArrayList<String>();
List<String> names = new ArrayList();  // Compiler generates warning
List<String> names = new ArrayList<>();  // <> should be used for auto type inferencing
<> operator may work when used within a method call, but recommended use is only in declaration.
[Ref



Other References:
- Talk/slides from the owner of Project Coin (JSR 334), Joe Darcy



Wednesday, December 21, 2011

Oracle Certified Professional Java SE 7 Upgrade Exam 1Z0-805

Upgrade Exam
Java SE 7 Features and Enhancements

The beta version of 1Z0-805 was 1z1-805, which ended on Jan 7, 2012.

Notes on 1Z0-805 Objectives:
External tutorials, notes, and references:

All Exam 1Z0-805 Objectives:

Language Enhancements [JSR 334]
1. String in the switch statement
2. Binary literals, numeric literals with underscores
3. try-with-resources

4. Multi-catch in exception statements
5. The diamond operator with generic declarations
6. More precise rethrow in exceptions   

Design Patterns
1. Design a class using the Singleton design pattern
2. Identify when and how to use composition to solve business problems  
3. Write code to implement the DAO Pattern
4. Design a class that uses the Factory design pattern
5. Database Applications with JDBC


Describe the JDBC API
1. Identify the Java statements required to connect to a database using JDBC
2. The JDBC 4.1 RowSetProvider, RowSetFactory, and new RowSet interfaces   
3. JDBC transactions
4. The proper JDBC API to submit queries and read results from the database.
5. JDBC PreparedStatement and CallableStatement  

Concurrency [JSR 166Y]
1. Identify potential threading problems
2. Use java.util.concurrent collections
3. Use atomic variables and locks
4. Executors and ThreadPools
5. Use the parallel Fork/Join framework

Localization
1. Describe the advantages of localizing an application
2. Define what a locale represents
3. Read and set the locale by using the Locale object
4. Build a resource bundle for each locale
5. Call a resource bundle from an application
6. Select a resource bundle based on locale
7. Format text for localization by using NumberFormat and DateFormat

Java File I/O (NIO.2) [JSR 203]
1. Use the Path class to operate on file and directory paths
2. Use the Files class to check, delete, copy, or move a file or directory
3. Read and change file and directory attributes
4. Recursively access a directory tree
5. Find a file by using the PathMatcher class
6. Watch a directory for changes by using WatchService

Tuesday, December 20, 2011

ssh_exchange_identification: Connection closed by remote host


Debug

"ssh -vvv" can be used for verbose debugging info to determine the cause of failing ssh.

Possible Solutions

[1] Concurrent SSH connections

The default number of concurrent copnnections allowed by sshd is usually only 10. If higher concurrent ssh are expected, increase the MaxStartups in /etc/ssh/sshd_config

This case it the most likely if some of the ssh from one machine to another works and rest get connection closed by remote host error.

[2] Corrupted SSH Keys

If even a single ssh from one machine to another doesn't work, then the SSH keys could have been corrupted. The best steps to follow in such a case is to do the following:
- Ensure correctness of /etc/hosts.allow and /etc/hosts.deny
- Remove ~/.ssh from both machines
- Start over ssh setup following my other post on SSH without password.


Excellent reference and additional details is available here.

Linux I/O Disk Schedulers

Available options are generally:

[1] Noop - It is a FIFO based simple scheduler

[2] Completely Fair Queuing [cfq]

[3] Anticipatory - older scheduler, now replaced by cfq

[4] Deadline - Tries to guarantee a service time

Check Current Scheduler

All available schedulers are listed and the current scheduler is placed within square brackets:

$ cat /sys/block/${DEV}/queue/scheduler
noop anticipatory [deadline] cfq

Change Scheduler for a Device

As a sample, changing the scheduler to noop:

$ echo noop > /sys/block/${DEV}/queue/scheduler
$ cat /sys/block/${DEV}/queue/scheduler
[noop] anticipatory deadline cfq

This change does not persist across reboots. The echo statement may be added to /etc/rc.local in order to execute it after every reboot.

Change Scheduler for all Disks

Instead of changing scheduler for a particular device, if it is desired to change the scheduler for all disks on the system, then elevator=<scheduler> can be added to the boot options in /etc/grub.conf.

Wednesday, December 7, 2011

Disable IPv6 in Linux


Before Disabling IPv6


Ensure you do not require ipv6. Some common modules that use ipv6 are:
rdma_cm, ib_addr, bnx2i, cnic

Configuration Changes to Disable IPv6

To disable ipv6 and prevent the module from loading, the following configuration files require changes:

[1] In RHEL 5 / OEL5 and earlier
/etc/modprobe.conf:

alias net-pf-10 off
alias ipv6 off
options ipv6 disable=1
# Will load true instead of ipv6 module
install ipv6 /bin/true

In RHEL 6 / Oracle Linux 6:
/etc/modprobe.conf is deprecated. Instead add a conf file with any name in /etc/modprobe.d, like:
/etc/modprobe.d/disable_ipv6.conf, with the following content:
alias net-pf-10 off
options ipv6 disable=1
install ipv6 /bin/true


[2] /etc/sysconfig/network:
NETWORKING_IPV6=no

Reboot for Changes to Take Effect


Verify that IPv6 Module is Not Loaded


The following command should not return anything:
/sbin/lsmod | grep ipv6

Wednesday, November 16, 2011

Export ext File System and NFS mount

The idea is to share a directory from the source machine and to mount it on another.

In RHEL / Oracle Linux or similar environments:  

On source machine host1

Add to /etc/exports:
<absolute-path-to-the-directory>  *(rw,sync,fsid=0)

Restart services:
$ /etc/init.d/portmap restart
$ /etc/init.d/nfs restart  

On destination machine host2

mount host1:<absolute-path-to-the-directory> <mount-point: empty-directory-path-on-host2="">

Tuesday, October 18, 2011

Disable SELinux


Check current status:
cat /selinux/enforce
1 => enabled
0 => disable
 
To disable SELinux:
  • Disable immediately withoput reboot, change will be lost upon reboot:
    echo 0 > /selinux/enforce
  • Reboot required:
    • Set selinux=disabled in /etc/selinux/config, then reboot
    • In grub boot command-line add: selinux=0, and reboot


[Ref] Excellent post with details available here

Wednesday, October 5, 2011

Linux Clock Source


There are various clock-sources available in Linux. It is important to select the right one for keeping a correct system clock, or to reduce time drifts and keep the system time in sync with a time source. Which clock-source you choose can affect performance too.

A good starting point is to determine which clocksources are available on your system and which one is currently in use.

cd /sys/devices/system/clocksource/clocksource0/
cat available_clocksource
cat current_clocksource

Excellent brief primer on various clocks: http://the-b.org/Linux_timers

Tuesday, September 20, 2011

Linux Per Process I/O Stats

# Enable block dump on devices
echo 1 > /proc/sys/vm/block_dump
# Check I/O operations per process
dmesg -c

Excellent article along with a nice script to summarize dmesg is here.

Monday, August 29, 2011

ESX/ESXi Bookmarks


Sunday, August 28, 2011

Clone VM in ESX without vCenter



Login to the ESX/ESXi console to clone vm1 datastore to vm2. 


$ cd /vmfs/volumes/datastore/
$ mkdir vm2
$ vmkfstools -i vm1/vm1.vmdk vm2/vm2.vmdk


Next, create vm2 from the client GUI and choose existing disk option pointing to the newly created vm2.vmdk. 


More details available in the excellent article here.


To read how to access the hidden ESXi console, refer to this article.



Thursday, August 25, 2011

Could not power on VM : No space left on device - Failed to power on VM

With VMWare's ESX or ESXi, "Could not power on VM : No space left on device - Failed to power on VM" is a common sight when trying to start a VM.

This error seems bizarre especially when you are actually trying to increase the guest RAM and the error is about disk space. The cause could be the following:
  1. By default, ESX will configure a swap on the VM's datastore equal to the RAM. So, when RAM is increased, more disk space is required. The fix is to reserve memory in resource allocation settings for the VM.
  2. There really isn't enough disk space on the datastore. Reduce Hard Disk size for the VM.

Enable/Disable Optional Oracle 11g Options


In Oracle database 11g, after installation, if you ever want to enable/disable the optional features, just shutdown your database and use the chopt utility as described below. Once done, restart the database and you are all set!

$ORACLE_HOME/chopt

Usage:

chopt <enable|disable> <option>

options:
                  dm = Oracle Data Mining RDBMS Files
                  dv = Oracle Database Vault option
                lbac = Oracle Label Security
                olap = Oracle OLAP
        partitioning = Oracle Partitioning
                 rat = Oracle Real Application Testing

e.g. chopt enable rat

Tuesday, August 9, 2011

Disable NIS in RHEL / Oracle Linux

Related configuration files:
/etc/host.conf - lists the lookup order. No change necessary.
/etc/nsswitch.conf - remove nis from hosts list
/etc/sysconfig/network - remove NISDOMAIN entry

Reboot.

Sunday, July 24, 2011

Missing cron.d in sysstat rpm install

This note is for RHEL/OEL or other similar distributions.

When rpm install for sysstat package complains of missing /etc/cron.d, while cron.d suggest missing cron package, the actual missing package is vixie-cron.

rpm -Ivh sysstat*.rpm
- dependency fails due to missing /etc/cron.d

rpm -qa|grep cron
- following should be installed, otherwise install these first:
  • crontabs-...
  • vixie-cron-...
  • anacron-...


Saturday, July 16, 2011

Basic Mercurial version control

1. Set username in ~/.hgrc:
[ui]
username=name<email>

2. Setup new project
cd YourProj
hg init
hg status
hg add
hg commit

3. Other frequently used commands:
hg log
hg help


http://mercurial.selenic.com/wiki/QuickStart

Monday, July 11, 2011

Sample vm.cfg file for Oracle VM

bootloader = '/usr/bin/pygrub'
disk = ['file:/OVS/seed_pool/vm/System.img,xvda,w']
memory = '512'
name = 'vm'
vcpus = 2
cpu = '0,1'
on_crash = 'restart'
on_reboot = 'restart'
vfb = ['type=vnc,vncunused=1,vnclisten=0.0.0.0']
vif = ['type=netfront,bridge=xenbr0','type=netfront,bridge=xenbr1']

Thursday, July 7, 2011

Tracking Intel Processors

06/2006: Woodcrest 2P 4c
11/2006: Clovertown 2P 8c [2x woodcrest chip in one]
11/2007: Harpertown 2P 8c

??/2007: Tigerton 4P 16c (no HT)  ["ton" => 4P]
09/2008: Dunnington 4P 24c (HT) [Last Penryn]
12/2008: Nehalem EP 2P 8c (HT) [Gainstown]
03/2010: Nehalem EX 4P 32c (HT) [Beckton]
01/2010: Westmere EP 2P 12c (HT) [Gulftown]
05/2011: Westmere EX 4P 40c (HT) 
01/2011: Sandybridge EP 2P 16c (HT)
??/2013: IvyBridge EP 2P 24c (HT)
??/201?: IvyBridge EX (IvyTown) (HT)
??/201?: Haswell

Thursday, June 16, 2011

Ethtool - Linux Networking tool

ethtool
 
See ethtool for the details. Here are a few frequently used ones:
# Get general info and connectivity status
/sbin/ethtool eth0
# Get driver info
/sbin/ethtool -i eth0  
 
# Get offload info
/sbin/ethtool -k eth0
# Set offload params. Eg. disable tcp and udp checksumming
/sbin/ethtool -K eth0 tx off
# To check checksum status:
tcpdump -vv -n -i eth0

Monday, June 6, 2011

WebLogic - myrealm failed to load exception

For WebLogic myrealm errors like below, the following could be tried:
  • Ensure hostname correctly resolves to the IP address in /etc/hosts
  • Check you configuration and validate encrypted password by running from the domain folder:
    java -cp <path_to_weblogic.jar> weblogic.security.Encrypt
  • If you are using database as the security store, try to run the script at $WLS_HOME\wlserver_10.3\server\lib\rdbms_security_store_oracle.sql on the database logged in as the weblogic user. 

<Error> <Security> <BEA-090870> <The realm "myrealm" failed to be loaded: weblogic.security.service.SecuritySe
rviceException: java.lang.ExceptionInInitializerError.
weblogic.security.service.SecurityServiceException: java.lang.ExceptionInInitializerError
        at weblogic.security.service.CSSWLSDelegateImpl.initializeServiceEngine(CSSWLSDelegateImpl.java:342)
        at weblogic.security.service.CSSWLSDelegateImpl.initialize(CSSWLSDelegateImpl.java:221)
        Truncated. see log file for complete stacktrace
Caused By: java.lang.ExceptionInInitializerError
        at com.octetstring.vde.util.guid.GuidGenerator.nextGuidInBytes(GuidGenerator.java:125)
        at com.octetstring.vde.util.guid.Guid.<init>(Guid.java:84)
        at com.octetstring.vde.backend.standard.BackendStandard.add(BackendStandard.java:379)
        at com.octetstring.vde.backend.BackendHandler.add(BackendHandler.java:460)
        at com.octetstring.vde.util.LDIF.importLDIF(LDIF.java:279)
        Truncated. see log file for complete stacktrace

Monday, May 23, 2011

Fixing Time Sync problem in Xen DOMU on Oracle VM Server

A 0 in the following suggests syncing time with DOM0:
/proc/sys/xen/independent_wallclock

However, when DOMU is unable to keep time sync with DOM0, the following may be tried:
echo 1 > /proc/sys/xen/independent_wallclock

If you have a ntpd setup elsewhere:
/usr/sbin/ntpdate <ntpd_server>

To update over the network:
rdate -s http://time-a.nist.gov

To manually set the date:
date -s "<date>

Updating Time Zone in Linux

Following should work on RHEL, Oracle Linux, Centos, Ubuntu, and similar may work on others:
Update /etc/sysconfig/clock with the desired timezone from /usr/share/zoneinfo
Backup current localtime:
mv /etc/localtime /etc/localtime.o
cp /usr/share/zoneinfo/ /etc/localtime

If the command is available, the above can be achieved by using:
system-config-date

Simple Oracle listener.ora

$ORACLE_HOME/network/admin/listener.ora:
listener= (ADDRESS_LIST =
(ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
)

SID_LIST_listener = (SID_LIST=
(SID_DESC=(SID_NAME=)(ORACLE_HOME=))
)


--

$ lsnrctl <start|stop|status>

Sunday, May 22, 2011

Drop missing data file on ORA-01110

* May not be appropriate in production env *

Sometimes in test env, if a datafile, which is no longer required, is deleted without first dropping the tablespace, then to cleanup:

startup mount;
alter database datafile '' offline drop;
alter database open;
drop tablespace including contents;

Configuring HugePages with Oracle JRockit JVM

Making JRockit JVM use Linux hugepages requires the following 2 configurations:

[1] Mount hugetlbfs
mount -t hugetlbfs nodev /mnt/hugepages
chmod 777 /mnt/hugepages

[2] Use JVM options
-XXaggressive: usually auto enables hugepages, and will use hugepages, if enough available
-Xlargepages: explicitely enables hugepages, and will use if enough hugepages are configured on the system
-Xlargepages:exitOnFailure=true: Will exit if could not use hugepages for any reason

Configuring RSH without Password

Tried on RHEL and Oracle Linux:

[1] Install rsh-server*.rpm from the Linux distribution for your system or using yum.

[2] Add the following to /etc/securetty:
rsh
rexec
rlogin

[3] Edit the rsh, rexec, and rlogin files in /etc/xinetd.d/ and change value of disable from yes to no

[4] /etc/init/d/xinetd restart

[5] Add list of hosts to /etc/hosts as:


[6] Add the hosts to ~/.rhosts as:


[7] chmod 600 ~/.rhosts
Also, ensure .rhosts is owned by the right user:group. Otherwise use chown as well.

[8] Repeat steps 1 to 7 on all hosts

Now, you should be able to rsh among the hosts on which you have setup rsh-server correctly.


Mounting RamFS, TmpFS, ISO image

Mount Ramfs
mount -t ramfs -o size=1g ramfs /mnt/ram

Remember that specifying size with ramfs does not limit the /mnt/ram. The ramfs is bound by the free RAM on the system, after which the system will start swapping and performance will be severely degraded.

Mount Tmpfs
mount -t tmpfs -o size=1g tmpfs /mnt/tmp

Mount ISO
mount -o loop,ro <img>.iso <destination>

[Ref] Nice article on Ramfs and Tmpfs available on thegeekstuff

SSH without Password

In order to ssh from Host1 to Host2 without password, the following needs to be done:

user1@Host1:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user1/.ssh/id_rsa):
Created directory '/home/user1/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user1/.ssh/id_rsa.
Your public key has been saved in /home/user1/.ssh/id_rsa.pub.

If ~/.ssh doesn't exist on Host2 as user2, create one:

user2@Host2:~> mkdir -p .ssh
user2@Host2:~> chmod 700 .ssh

Append user1's public key to authorized_keys and authorized_keys2 in user2@Host2:.ssh/:

user1@Host1:~> cat .ssh/id_rsa.pub | ssh user2@Host2 'cat >> .ssh/authorized_keys'
user1@Host1:~> cat .ssh/id_rsa.pub | ssh user2@Host2 'cat >> .ssh/authorized_keys2'

user2@Host2:~> chmod 640 .ssh

Now ssh from user1@Host1 to user2@Host2 should be possible without password:
user1@Host1:~> ssh user2@Host2\

Avoid Host Verification

ssh -o "StrictHostKeyChecking no" user@host

Debugging

Set LogLevel to DEBUG in /etc/ssh/sshd_config
/etc/init.d/sshd restart
Then try to ssh, debug messages will be logged to /var/log/secure
PS: Once you have resolved the issue remember to switch back LogLevel to INFO and again restart sshd.

Editing Xen System.img

This post is useful when you want to change system configuration files of a stopped guest VM without botting up the guest first. This method can be used especially when your guest VM crashes or hangs during boot up due to a configuration error.


The following steps have been tested on Xen 4 and Oracle VM 2.2 as well for a Linux guest VM. From DOM0: 


Check FS Type
fdisk -u -l System.img

If FS type is ext3, you can directly mount a partition using lomount, otherwise follow the mounting LV's steps.

Mount Ext3 Partitions

Linux system.img with ext3 partitions can be mounted as:
lomount -diskimage System.img -partition 2 /mnt

Mounting LV's

# Mounting guest's root partition locally
# Find a free loop device
loop_dev=`losetup -f`

# Now bind the image file to that loop device
losetup ${loop_dev} System.img

# Next, scan the loop device for partitions
kpartx -av ${loop_dev}

# If /dev/mapper doesn't list LVs for the partitions from kpartx, find LV:
vgscan
vgchange -ay sysvg

# Mount the desired LVM
mount /dev/mapper/loop0p2 /mnt

LVs UnMounting
# After editing in /mnt, unmount and remove partitions:
umount /mnt

# Disable the LV
vgchange -an /dev/mapper/loop0p2

# Remove the discovered partitions
kpartx -dv ${loop_dev}

# Delete the loop device
losetup -d ${loop_dev}