Skip to content

Category: english

Trying to corrupt data in a ZFS mirror


Ilustrative image 😛

This is the first of a serie of posts I’d like to write while I’m studying more about OpenSolaris. The idea is to create simple posts showing a specific feature through practical examples that you can reproduce in your computer.

One of the most interesting feature on OpenSolaris is the 128-bit filesystem ZFS.
For those who are starting with ZFS, the main diference is the abstraction used for volumes. Unlike traditional file systems, which reside on single devices and thus require a volume manager to use more than one device, ZFS filesystems are built on top of virtual storage pools called zpools. One zpool is constructed of virtual devices (vdevs), which are themselves constructed of block devices: files, hard drive partitions, or entire drives (the recommended usage).

In this first experiment we will construct a mirrored zpool (RAID-1) and so try to corrupt its data and see what happens. In a mirrored pool the data is replicated into many disks and that eliminates the critical point, ie if one disks stops the data is not corrupted. You’ll can create a mirror with two or more disks and inside a pool you can have many mirrors. By example, one pool of 100Gb made by two mirrors, each one with 50Gb and each mirror made by volumes of 25Gb. You’ll scale your pool according your needs and capabilities.

This part of corrupt data make this experiment a little dangerous. You have these options:

  • Install OpenSolaris in your disk and have at least two more disks to make a mirrored zpool. I don’t recommend this option because if you don’t know exactly what you are doing you can lose important data if you use the wrong volumes.
  • Install OpenSolaris in a virtual machine and create fake volumes for this experiment. If you make some mistake nothing too bad will happen. That’s the option I’m using. Here I’m using VirtualBox with OpenSolaris 2008.5. VirtualBox is a free virtual machine, easy to use and works well with OpenSolaris.

Although there is already a graphical tool for manage ZFS, this is not available at OpenSolaris 2008.5. Also for who are studying ZFS a little bit deeper, know how to manage it by command line tools is interesting.

With your OpenSolaris booted, open a terminal and log yourself as root. Consult your available devices with echo|format.

If you are familiar with Linux, OpenSolaris nomenclature for devices may sound strange. I recommend you to take a look at this document.

To create a pool with the devices c4d1 (80G) and c5d1 (60GB) just type zpool create ourpool mirror c4d1 c5d1.

Explaining this command word by word:

  • zpool: for manage ZFS you need to be familiar with only two commands: zpool and zfs. Zpool command is for configure and manage ZFS pools.
  • create: the action, in this case, creation.
  • ourpool: name I chose for the pool.
  • mirror: we want a mirror in ourpool, so the next words will be more devices.
  • c4d1 c5d1: devices we want to use.


Diagram of ourpool. Icons from Everaldo Coelho.

If your command works, it’ll works silently e will returns nothing. For check pool’s status do a zpool status ourpool.

This output shows that a pool called ourpool is ONLINE and is made of one only mirror, that is made of two devices c4d1 e c5d1.

We can list all pools with zpool list.

Ourpool has approximately 60Gb size which 900kb is already used for store metadata. As we did a mirror using volume of 60Gb and 80Gb, the mirror size is determined by the smaller volume. The another pool, rpool is a pool that OpenSolaris creates by defaul to place the system.

Now we’ll populate the pool with data. These data could be real important data like data base files, your photo collection or personal documents. For illustrative effect I’m using a 100Mb empty file called data. mkfile 100m data.

While the file creation I did a zpool iostat -v ourpool too see the IO traffic in the pool. Note that there’s traffic on both disks as they form a mirror.

We will create and save a file of md5 checksum of date to be able to check its integrity later, md5sum data > data.md5. Too see if a checksum matches we do a md5sum –check data.md5.

Now comes the critical part of this simulation. We will simulate a physical defect on the disc. Storage devices will fail at some point, but we don’t know when. When it happens it can corrupt your data or stop important applications.

Let’s get 20Mb of garbage from /dev/urandom e throw them in the disk c4d1, dd if=/dev/urandom of=/dev/dsk/c4d1 bs=1024 count=20480. There’s more fun (and expensive) ways to case physical defects in a disk, take a look into this video where they use ZFS and hammers. 🙂

Ready, the damage was done. Let’s look the pool status, zpool status ourpool.

We see no error but the ZFS uses strongly memory cache. Let’s force clean this cache by disabling and enabling the pool. First cd / to assure we are not into the pool, so zpool export ourpool followed by zpool import ourpool.

Checking it’s status again, zpool status ourpool.

Pool remains ONLINE but ZFS noticed that something is wrong.

Let see the data integrity, md5sum –check data.md5.

Data are intact.

This is one of the characteristic of self healing in ZFS. The corruption that occurred in one volume was silently repaired. In a traditional volume manager you would not only lost our data but not event know that a corruption has occurred.

In this point the system administrator should be warmed to take some action on the defective disk. Here some advices:

  • Find out the defective disk: if the disk fails once so is probably that it’ll fail again or even take others disks to fail. ZFS have a mechanism called scrubbing that scan blocks finding out checksum erros and trying to correct them using the safe data. A zpool scrub ourpool will force the scrubbing process, that will run in background. After that If you look at the pool status zpool status ourpool you can see which disk is the defective one.
  • Look the pool history: you can examine all pool history and understand all that happening before you came. A zpool history ourpool will show all commands that was used since its creation.
  • Repair de mirror: a zpool clean ourpool will repair the mirror, but keeps the defective disk, what can be dangerous.
  • Turn off the defective disk: you can turn off it using a zpool offline ourpool c4d1 without alter the pool structure.
  • Unmirror the pool: with a zpool detach ourpool c4d1 you can remove the device from the pool, but as the mirror was composed of two devices, it’s no longer a mirror.
  • Change the defective disk: if you have another disk, like c6d1, you put it in the place of the defective disk and it’ll assume it role in the mirror. For that use a zpool replace c4d1 c6d1. This will start in background a process called resilvering, but that is subject for another post. 🙂

I also did a screencast the resumes the entire process:


Video download: opensolaris_zpool_mirror.mpeg.

Additional Documentation:

This post is a english translation for this post.

CEJUG, JavaMe, Domain Driven Design and CruiseControl

This saturday we had our CEJUG traditional event CCT (Café com Tapioca) done monthly, each time in a diferent university. This time we had three speakers, Vando Batista, Rafael Pontes and Luthiano Vasconcelos talking about Java ME, Domain Driven Design and Cruise Control respectively.

Rafael Carneiro
Rafael Carneiro opening the event.

Wando

All photos I took (just a few due to weak batteries in my camera) are hosted in this album. This was out first event recorded and streamed by TV Software Livre. Thanks also guys from ArgoHost who made it possible.

OpenSolaris at InfoBrasil 2008

Me and people talking about OpenSolaris

InfoBrasil is a tradicional IT business event in my city. This year we got a space for Open Source and Free Software where I did a presentation about OpenSolaris. I posted our grid yesterday.

That was my first presentation about OpenSolaris so I focused to showing that OpenSolaris 2008.5 is a  GNU/OpenSolaris distribution but you can access features like ZFS, DTrace and Zones. I used those slides that Tirthankar Das, Solaris Cluster Engineering at Sun Microsystems, did for FISL 2008. Most of the audience was composed from students and they showed very impressed with ZFS. In my next OpenSolaris presentation I’ll try to focus more on ZFS demos. 😉 Someone in the audience did a random number generator code live. We used it to prize some OpenSolaris gifts like tshirts and sticks. 😀

OpenSolaris in action

I hope that for now on that we can use better this space and for establish a good dialog between communities, governments and enterprises.

All photos ares avaliable at my personal album for that event.

Crawford Beveridge in Brazil

This monday I and others ambassadors from all over Brazil went to São Paulo to have a quick meeting with Crawfor Beveridge, executive vice president and chairman, EMEA, APAC and the americas at Sun Microsystems.

Ambassadors

As we cant see all ambassadors at FISL was a good oportunite to meet all brazilians ambassadors, olds and new ones. Lucas Torri bring to us some cool OpenSolaris shirts and gifts from JavaOne 2008 (where he was showing Project Marge).

Dukes

Sun gadgets

I could also see some places in I don’t knew in the building, like the room for demostrating products. I saw very interesting backup devices from Storage Tek (now also part of Sun).

Maluf introduces us
Maluf introduces us to Crawford

Jomar Silva
Jomar Silva

Eduardo Lima
Eduardo Lima

We had an presentation with Jomar Silva, General Director of the Brazilian Chapter of the ODF Alliance, about ODF advances in Brazil. Eduardo Lima showed details of Sun Campus Ambassador Program in Brazil and also this cool videos about Open Source and OpenSolaris made by Vitório Sassi, Bruno Souza and Rafael Tinoco.

Crawford Beveridge

Crawford and me
Me and Crawford Beveridge.

NE pizza meeting
Almost all northeast ambassadors in a quick pizza dinner in the airport.

The complete album is available here.

International Free Software Forum 2008

Every year in Porto Alegre, Brazil, is placed the biggest free software event in the world. Is the International Forum on Free Software, FISL. This year the event counted with 21 countries, 257 presentations and more than 7 thousands hackers, students, developers and entrepreneurs together sharing knowledge and making friends.

FISL 2008 Theater

Just a few hours after NetBeans in Fortaleza. I was flying to a long trip to Porto Alegre (almost a entire day) to join in three events, the FISL 9.0 itself and also OpenSolaris Day Porto Alegre and Javali 2008.

Solaris Express and Coffee express
I like my coffee like my Solaris, Express. 😛 Installing a newer version during a free time in the airport.

At OpenSolaris Day I presented High Performance Computing and OpenSolaris showing an introduction about parallel computing concepts and a little bit about how to take advantage of OpenSolaris for HPC, using tools like ZFS and Dtrace for OpenMPI. Was a good presentation and I got good questions.

Audience

Me on OpenSolaris Day

Me on OpenSolaris Day

After the OpenSolaris Day/Javali 2008 we all had a pizza party. I was really sick during my presentation, I’m not familiar with temperatures beyond 25° and that day was 8°.

Pizza party

Some Sun Campus Ambassadors

The presentation I prepared for FISL was “NetBeans: Beyond Java” showing a little bit how you can use NetBeans to develop using Ruby, C, C++ and others languages. I’d like to show that NetBeans is more than a Java IDE. I showed more about the Ruby and Ruby and Rails integration.

Some photos:

NetBeans on FISL

NetBeans on FISL

NetBeans at FISL

My second presentation on FISL was about JavaFX. This presentation was not really planned and I have just a couple of days to organize it. Fortunately I contacted the JavaFX community from openjfx project and immediately I got a lot of help to build some material. A very sincerely and special thanks for James L. Weaver who helped me immediately a lot. Thanks too to the Planet JFX community and their material.

JavaFX on FISL

JavaFX on FISL

JavaFX on FISL

Was really a good demo. I was more relaxed than in my Netbeans presentation and also I got a excellent feedback.

More photos:

OpenSolaris User Group

OLPC XO

OpenSolaris
Thirtankar Das talked about project Indiana.

Man and child using their laptops

Rafael Vanoni talking about OpenSolaris Kernel
Rafael Vanoni talking about OpenSolaris kernel scheduling.

Roger Brinkley
Roger Brinkley talking about PhoneME.

high 5

Fracois Orsini, Silveira Neto and Ted Goddard
Fracois Orsini, me and Ted Goddard.

Gregg Sporar
Gregg Sporar on Java memory leaks.

Raghavan
Raghavan “Rags” Srinivas on Java runtime.

Louis Suarez-Potts and Vitorio. Furusho
Louis Suarez-Potts and Vitorio Y. Furusho talking. See also this excellent interview with Louis.

Ray Gans
Ray Gans on OpenJDK.

Rich Sands on OpenJDK
Rich Sands also on OpenJDK.

Meet Sun SPOT
Gary Thompson showing a Sun SPOT vehicle.

Rafael David Tinoco
Rafael David Tinoco on UltraSparc and OpenSparc.

Campus Party on FISL
Sérgio Amadeu da Silveira, Roberto Andrade e Marcelo D’Elia Branco in a informal retrospective about Campus Party.

Marge
Lucas Bortolaso Torri and Bruno Cavaler Ghisi talking about Marge Framework.

Rich Sands, me and Eduardo Lima
Rich Sands, me and Eduardo Lima

Be at FISL was a dream for me for a long time and finally I could achieve this year, and more specially participating as speaker. In the other hand, I spent lot of time finishing and preparing my demos and could not completely enjoy the event itself, but was a really good event, I meet a lot of people I only knew by mails lists and also meet a lot of people from Sun’s staff.

Porto Alegre

Porto Alegre

Dinner

Porto Alegre is also a very beautiful and well preserved city though I had almost no time to see it. And if during the daytime I almost don’t ate, during the night I went to very good restaurants and churrascarias. I went back to home some kilos fatter. 😛

  • ps.: I took hundreds of photos. There a set of them in my Flickr.
  • ps. 2: I tried to put the name of all who appeared in my photos. If I did a mistake, let me know, please.
  • ps. 3: I had a problem with my file system and I lose those slides I presented in FISL. 🙁 The only available is High Performance Computing and OpenSolaris.

Java key listening example

This post continues a serie of posts I’m writing about 2D game development in Java.
A simple example of an JPanel that implements KeyListener (and a little trick) to handle KeyEvents to move a white square.

Java KeyListening Example

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class KeyPanel extends JPanel implements KeyListener{
    private int x=50,y=50;
    public KeyPanel() {
        JTextField textfield = new JTextField();
        textfield.addKeyListener(this);
        add(textfield);
        textfield.setPreferredSize(new Dimension(0,0));
    }

    public void keyTyped(KeyEvent e) {}

    public void keyReleased(KeyEvent e) {}

    public void keyPressed(KeyEvent e) {
        if (e.getKeyCode() == KeyEvent.VK_LEFT)
            x-=5;
        if (e.getKeyCode() == KeyEvent.VK_RIGHT)
            x+=5;
        if (e.getKeyCode() == KeyEvent.VK_DOWN)
            y+=5;
        if (e.getKeyCode() == KeyEvent.VK_UP)
            y-=5;
        this.repaint();
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.black);
        g.fillRect(0, 0, 500, 500);
        g.setColor(Color.white);
        g.fillRect(x, y, 50, 50);
    }
}

Download the complete NetBeans source project files: KeyTest.tar.bz2.

Simple Java Tileset Example

Tilesets are a common technique in game development to create all kinds of tile-based games (from strategy to RPG games).

Here’s a example of simple 2D isometric square tilesets. I decided to use 32×32 pixels tiles and store 10 tiles per row in a single image:

I created a class called public class JGameCanvas that extends from JPanel from swing:

package game;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JPanel;

enum Tile {
GRASS, GRASS_STONE, GRASS_BAGS, T3, T4, T5, T6, T7, T8, T9,
TREE, TREE_CHOMP, TREE_DEAD, T13, T14, T15, T16, T17, T18, T19,
ROAD_H, ROAD_V, ROAD_HV_DOWN, ROAD_HV_UP, ROAD_VH_RIGHT, ROAD_VH_LEFT, ROAD_CROSS, T27, T28, T29,
WALL, WALL_POSTER, WALL_END_RIGHT, WALL_END_LEFT, T34, T35, T36, T37, T38, T39,
T40, T41, T42, T43, T44, T45, T46, T47, T48, T49,
NEWS, T51,      RES_1, RES_2, BUSS_1, BUSS_2, HOSP_1, HOSP_2, MARK_1, MARK_2,
PIZZ_1, PIZZ_2, RES_3, RES_4, BUSS_3, BUSS_4, HOSP_3, HOSP_4, MARK_3, MARK_4,
PIZZ_3, PIZZ_4, RES_5, RES_6, BUSS_5, BUSS_6, HOSP_5, HOSP_6, MARK_5, MARK_6
}

public class JGameCanvas extends JPanel{
    private static final int tW = 32; // tile width
    private static final int tH = 32; // tile height
    private static final Tile map[][] =
    {{Tile.TREE,Tile.TREE, Tile.TREE, Tile.ROAD_V, Tile.GRASS, Tile.TREE, Tile.TREE_DEAD, Tile.GRASS_STONE, Tile.TREE, Tile.TREE},
     {Tile.WALL, Tile.WALL_POSTER, Tile.WALL_END_RIGHT , Tile.ROAD_V, Tile.WALL_END_LEFT, Tile.WALL, Tile.WALL_END_RIGHT, Tile.TREE_CHOMP, Tile.GRASS_STONE, Tile.GRASS_STONE},
     {Tile.GRASS,Tile.GRASS, Tile.GRASS_STONE, Tile.ROAD_V, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS},
     {Tile.PIZZ_1,Tile.PIZZ_2, Tile.GRASS, Tile.ROAD_V, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS},
     {Tile.PIZZ_3,Tile.PIZZ_4, Tile.GRASS, Tile.ROAD_V, Tile.GRASS, Tile.GRASS, Tile.MARK_1, Tile.MARK_2, Tile.HOSP_1, Tile.HOSP_2},
     {Tile.ROAD_H,Tile.ROAD_H, Tile.ROAD_H, Tile.ROAD_VH_LEFT, Tile.TREE, Tile.TREE_DEAD, Tile.MARK_3, Tile.MARK_4, Tile.HOSP_3, Tile.HOSP_4},
     {Tile.GRASS,Tile.BUSS_1, Tile.BUSS_2, Tile.ROAD_V, Tile.TREE, Tile.NEWS, Tile.MARK_5, Tile.MARK_6, Tile.HOSP_5, Tile.HOSP_6},
     {Tile.GRASS,Tile.BUSS_3, Tile.BUSS_4, Tile.ROAD_VH_RIGHT, Tile.ROAD_H, Tile.ROAD_H, Tile.ROAD_H, Tile.ROAD_H, Tile.ROAD_H, Tile.ROAD_H},
     {Tile.GRASS,Tile.BUSS_5, Tile.BUSS_6, Tile.ROAD_V, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS},
     {Tile.GRASS,Tile.GRASS, Tile.GRASS, Tile.ROAD_V, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS}
    };

    private Image tileset;

    public JGameCanvas() {
        tileset = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("resources/tileset.png"));
    }

    @Override
    protected void paintComponent(Graphics g) {
        g.setColor(Color.black);
        g.fillRect(0, 0, getWidth(), getHeight());

        for(int i=0;i<10;i++)
            for(int j=0;j<10;j++)
                drawTile(g, map[j][i], i*tW,j*tH);
    }

    protected void drawTile(Graphics g, Tile t, int x, int y){
        // map Tile from the tileset
        int mx = t.ordinal()%10;
        int my = t.ordinal()/10;
        g.drawImage(tileset, x, y, x+tW, y+tH,
                mx*tW, my*tH,  mx*tW+tW, my*tH+tH, this);
    }
}

Program running:

Those graphics I created for the game Batalhão and are under Creative Commons Attribution Share Alike 3.0 license. The source code is under GPL license, download the NetBeans project with sources: tileset.tar.bz2.

NetBeans Day Fortaleza with Gregg Sporar

Gregg Sporar and CEJUG

Those days Gregg Sporar, NetBeans enthusiast working at Sun Microsystems was here in Brazil and went to our city Fortaleza to speak in our NetBeans Day Fortaleza. We had only a couple of days to prepare everything but is always good work under such pressure. 🙂

Me at the airport

Me and my friend (Cassiano Carvalho) could toke care of him. First we got Gregg at our international airport, Pinto Martins from a flight from Recife. After that we went to a typical food dinner at Coco Bambu where’s Gregg could taste our tapioca and figure why our local JUG (CEJUG) event is called Tapioca with Coffee.

Gregg tasting Tapioca

After that we went to the hotel but we did not have realized that that day was the birthday of our city Fortaleza and the birthday party was a public concert at beach of one of most famous artist in Brazil, Roberto Carlos.

Roberto Carlos in the early years
Roberto Carlos in the early years… 😛

For those who are not Brazilians, To have an idea what Roberto Carlos is, just imagine (in a smaller proportion of course) some kind of Brazilian Elvis Presley. When we quited the restaurant the show was just finished, we had a huge crowd walking back for everywhere, streets blocked, mess and traffic extremely slow. We spend about two hour on this. We decided to park the car, get Gregg’s luggage and go walking the hotel. Luckily the rain don’t caught us.

Rainy Day

In the morning was raining cats and dogs at Fortaleza, what is very uncommon.

Gregg cheking out

I picked Gregg at the hotel to the campus so we can meet the NPD (acronym in Portuguese for Data Processing Core) building, the Internet backbone of the entire state and where some projects are using NetBeans. Gregg also met our CS department, our labs and our cluster.

While that we prepared the auditorium and some last details, test microphones and projector.

P4140007 P4140006

People started to get and we got their names and mails for event certifications. I opened the event talking about NetBeans, CEJUG projects and opportunities for the students.

P4140019

P4140024

People from TV Software Livre (Free Software Television) was there too to record and transmit the event.

P4140017 P4140025

The first Gregg’s talk was about NetBeans and some new features from the last version of NetBeans and some new features for the version 6.1.

P4140045

The second was about Memory Leaks in Java and a method for detecting those. Very interesting.

Gregg Sporar

NetBeans Day Fortaleza

NetBeans Day Fortaleza

NetBeans Day NetBeans Day Fortaleza

Gregg Sporar

After Gregg quited to fly to Brasilia I did a presentation on NetBeans 6 and 6.1 Beta news features. You can download Gregg’s slides here and here, my slides here.The recorded video is hosted at Google Video. You can see more photos in this album:

Gregg Sporar

Gregg, thank you very much and hope you liked your quick visit to Fortaleza. 😉 Thanks also CEJUG and all guys that made this event possible.