How to Build Microsoft Graph Engine on Red Hat Linux

Microsoft Graph Engine is a distributed in-memory data processing engine. It’s an open source project but the official instructions claim that for Linux, it only supports Ubuntu 16.04. But what if you’re using other distributions of Linux, like Red Hat? Well, it’s possible but it does take quite some effort to build the source. Let’s get started.

Prerequisites:

  1. You need 64 G of RAM. Otherwise, you’ll run into “virtual memory exhausted” errors during the build process.
  2. As of 12/11/2018, if you build the latest commit of the source, the output binary won’t work with Linux. I filed this issue and until it’s resolved, you should check out earlier commits.

Install required software packages:

You need git, dotnet, openssl, and c++

sudo yum upgrade -y
sudo yum install git rh-dotnet22 openssl-devel -y
sudo yum install gcc-c++ libgcc.i686 glibc-devel.i686

Build GCC

No, devtoolset won’t work due to ABI compatibility issue. You HAVE TO build GCC 5.4 or higher. This also takes the longest time (a couple of hours).

Please follow the official instruction. I chose GCC 7.4 and I only built C & C++. So the commands I used were

wget ftp://ftp.gnu.org/gnu/gcc/gcc-7.4.0/gcc-7.4.0.tar.gz
$PWD/../gcc-7.4.0/configure --prefix=$HOME/GCC-7.4.0 --enable-languages=c,c++

Set the right environment variables

These are necessary for building CMake and later the Graphic Engine.

export PATH=~/GCC-7.4.0/bin:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/GCC-7.4.0/lib:~/GCC-7.4.0/lib64
export CC=~/GCC-7.4.0/bin/gcc
export CXX=~/GCC-7.4.0/bin/g++

Build CMake

Since CMake 3 is needed, you have to build it from its source. It’s very quick though. One thing to note is, when doing the “make install”, you have to be root. You need to re-export LD_LIBRARY_PATH

sudo -s
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<absolutepathtoGCClib>:<absolutepathtoGCClib64>
make install

Build Graph Engine

Finally, we’re ready to build the source of Microsoft Graph Engine. Exciting?! As mentioned earlier, I checked out an earlier commit:

git clone https://github.com/Microsoft/GraphEngine.git
git checkout 4175d13a084453bd2a2bf43adf1cc4e76f9fe417
cd GraphEngine/
scl enable rh-dotnet22 bash
tools/build.sh

Voila, you have the Nuget package built under the build/ folder!

MySQL with Entity Framework Core in ASP.NET Core

.NET Core offers.NET developers a great way to create cross-platform applications. If you want to create a web app with some database support, most likely you will use Entity Framework (EF) Core and ASP.NET Core. In this blog post, I’d like to give you some tips if you choose to use MySQL.

1. Db Provider choice

Although there’re a few MySQL providers to choose from in the official EF Core Docs site, I would recommend the most popular Pomelo.EntityFrameworkCore.MySql. I tried other providers and it gave me issues here and there.

Specifically, you can use the following code to add a DbContext in your service configuration:

services.AddCors();

services.AddDbContext<KnowledgeContext>(options => options.UseMySql(Configuration[“MySqlConnStr”]));

services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

And don’t forget to pass the DbContext to your controller’s constructor.

2. Use Fluent API instead of Data Annotation

This is more of an EF Core tip than a MySQL one. Certain restrictions such as foreign keys can only be specified with  the Fluent API.

3. Where to call Database.EnsureCreated

Again, an EF Core tip. DbContext.Database.EnsureCreated() is new method to ensure that the database and the required schema for the context exist. The database and the schema will be created if they don’t exist. However, in ASP.NET Core, every time a request comes, a controller’s constructor is called. So you probably want to put the EnsureCreated call in the Startup class. Please refer to https://stackoverflow.com/questions/36958318/where-should-i-put-database-ensurecreated.