Archive for June, 2007

The Little Known C# ?? Operator

I recently stumbled upon a little known operator in C#, that is pretty slick. It’s the “??” operator. Yeah, that’s right, it’s just 2 question marks. Unfortunately it’s nearly impossible to find anything in Google about it, since they don’t let you search for characters.

Anyway, this operator is great because it’s basically like the SQL IsNull or Coalesce. You can take multiple values, and get the first non-null value.

For example:
object a, b, c, d;

b = null;
c = null;
d = new object();
a = b ?? c ?? d;

Assert.AreEqual(a, d);

I wish I had known about this earlier, it’s pretty cool.

For more information, here is the direct MSDN documentation about it.

Also, I’m going to try to list some search terms for anyone looking for information about this. Hopefully Google will index them:
question mark question mark
double question mark
.NET 2.0 coalesce
question mark operator

New Server Running Great & Boots Windows in 5 seconds!

I’ve had my new server up and running for a couple of weeks now. It was definitely a great purchase. It’s unreal how powerful this thing is for around $600. It’s an Intel Core 2 Duo E4300 1.8, but I easily overclocked it to 3.0 GHz. At that speed this thing FLIES. I was actually pretty shocked when I realized that my Windows virtual machines will boot in about 5 seconds (sometimes less actually). I suspect it has something to do with Linux being able to intelligently cache the virtual hard drive.

The server itself is running Ubuntu Linux Server 64-bit, so that I can go above 4GB of memory if I need to. It’s running as a file server, a mail server, a subversion server, and a VMware server.

This server has taken everything I’ve thrown at it. Running 5 virtual machines, with a couple of them running a build? Not a problem. Running a backup while recompiling the kernel while serving mail? This thing idles at .1 - .5% CPU usage with 4 virtual machines running while fetching and serving mail. This is what VMware was made for.

Ok, so that’s the good news.

When I first tried to install the OS, Linux kept hanging at “Installing hardware drivers”. I tried different distributions including 32-bit, 64-bit, desktop, server, Cent OS, etc. I finally tried removing 2 of the 1GB memory chips, and it started working. I lived without that memory for a while actually. Then, once I got Linux installed, I would get random messages on the screen about network errors. I tried putting in a Gigabit network card to replace the onboard NIC. That worked, so I came to the conclusion that I had a bad network card.

I then decided to send back the motherboard (a Gigabyte GA-965P-S3), and got a version with solid state capacitors (GA-965P-DS3, whole different story) and a different type of network card. I figured I had better stay away from the kind that already failed on me. The 4GB of memory still wouldn’t work, no matter what I did. I even ordered another 2GB so that I could determine if some of the memory was bad. Still no lock. Then, I found some information online about a guy that had the same board, and the same problem. He disabled the “intel_agp” module, and it fixed it for him. I tried the same thing, and I was finally rockin with 4 gigs.

FYI, to disable the “intel_agp” module in Ubuntu, add that module name to the /etc/modprobe.d/blacklist file.

Ok, so now I was rocking with 4GB of memory, and no random errors. Now I was ready to move over my software RAID array from my old server. I put the drives in, and powered it up. It was a little scary because I didn’t have a local backup of the 300GB of data. It’s all in CA, which would take weeks to re-download. The server started up, and said the RAID array was invalid because it couldn’t find the superblocks. I had that horrible sinking feeling. Yeah, you know the one.

I kept trying to rebuild the array in every way I knew, but nothing would work without the proper superblocks on the drives. Thankfully, I found another post online from someone with the same problem (that always saves me). He said that once he got over his fear of deleting data, he was able to fix his array. The key is to re-create the entire array, but tell it to assume the drives are “clean”. This means that all of the data will be preserved, but the RAID superblock information will be re-written.

This line worked like a charm: sudo mdadm –create –verbose /dev/md0 –level=1 –raid-devices=2 –assume-clean /dev/sd[ab]