DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Manage Microservices With Docker Compose
  • Common Performance Management Mistakes
  • 7 Microservices Best Practices for Developers
  • The Importance of Persistent Storage in Kubernetes- OpenEBS

Trending

  • From Fragmentation to Focus: A Data-First, Team-First Framework for Platform-Driven Organizations
  • Key Considerations in Cross-Model Migration
  • How To Replicate Oracle Data to BigQuery With Google Cloud Datastream
  • Unlocking the Potential of Apache Iceberg: A Comprehensive Analysis
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. NoSQL Support for Hyperlambda

NoSQL Support for Hyperlambda

NoSQL database systems is one of those things you simply can't ignore today. Simply because of handling huge amounts of data becomes impossible without it.

By 
Thomas Hansen user avatar
Thomas Hansen
DZone Core CORE ·
Jan. 24, 22 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
3.5K Views

Join the DZone community and get the full member experience.

Join For Free

Handling huge amounts of data is literally impossible without having some sort of relationship to NoSQL database systems, such as Cassandra or ScyllaDB. The reasons are because these database systems are created to scale linearly, implying they're just as fast with a billion records as they are with 50 records. Hence, building things such as Twitter or Facebook is impossible without the ability to use NoSQL.

Hyperlambda has always suffered from lack of official support for such NoSQL database systems. However, yesterday that change with the release of Magic version 10.0.19. Out of the box you can now as of the latest release of Magic and Hyperlambda connect to any Scylla or Cassandra based cluster, retrieve records, and do any of the main CRUD operations towards your data storage. And as an additional kicker you can exchange the default RDBMS based logger with a NoSQL equivalent.

The thing I am personally most jazzed about though, is the ability to exchange the file system with a "virtual file system". This is because it allows you to create and maintain 100% perfectly stateless Magic instances, put these into containers, and use Kubernetes to load balance between hundreds of Magic instances if you wish - Yet still have these behave as one single instance. However, if you want to try this route, you'll have to first create a "files" table. Below is an example of how to do this in Cassandra and ScyllaDB.

CQL
 
create keyspace if not exists magic
   with replication = {
      'class': 'NetworkTopologyStrategy',
      'replication_factor': 5
   };

use magic;

create table if not exists files(
   tenant text,
   cloudlet text,
   folder text,
   filename text,
   content blob,
   primary key((tenant, cloudlet), folder, filename));

When you have created your table you can insert whatever files you've got locally by using the following snippet of Hyperlambda. Notice, you'll have to modify your "tenant" and "cloudlet" parts according to how your files are stored locally on your own machine. Use the "Eval" menu item in Magic to execute the following Hyperlambda.

Plain Text
 
/*
 * Inserts all dynamic files and folders into the magic CQL database.
 */
cql.connect:[generic|magic]

   /*
    * The root folder where your Magic backend is running.
    */
   .tenant:Users
   .cloudlet:"thomashansen/Documents/projects/magic/magic/backend"

   /*
    * Inserting root folder.
    */
   cql.execute:"insert into files (tenant, cloudlet, folder, filename) values (:tenant, :cloudlet, '/files/', '')"
      tenant:x:@.tenant
      cloudlet:x:@.cloudlet

   /*
    * Inserting appsettings.json and its folder.
    */
   config.load
   convert:x:-
      type:bytes
   cql.execute:"insert into files (tenant, cloudlet, folder, filename, content) values (:tenant, :cloudlet, '/config/', 'appsettings.json', :config)"
      tenant:x:@.tenant
      cloudlet:x:@.cloudlet
      config:x:@convert
   cql.execute:"insert into files (tenant, cloudlet, folder, filename) values (:tenant, :cloudlet, '/config/', '')"
      tenant:x:@.tenant
      cloudlet:x:@.cloudlet

   /*
    * Inserting folders.
    */
   io.folder.list-recursively:/
      display-hidden:true
   for-each:x:-/*

      strings.concat
         .:/files
         get-value:x:@.dp/#
      
      cql.execute:"insert into files (tenant, cloudlet, folder, filename) values (:tenant, :cloudlet, :folder, '')"
         tenant:x:@.tenant
         cloudlet:x:@.cloudlet
         folder:x:@strings.concat

   /*
    * Inserting files.
    */
   io.file.list-recursively:/
      display-hidden:true
   for-each:x:-/*

      io.file.load.binary:x:@.dp/#
   
      strings.split:x:@.dp/#
         .:/
      unwrap:x:+
      .filename:x:@strings.split/0/-
      remove-nodes:x:@strings.split/0/-
      strings.join:x:@strings.split/*
         .:/
      strings.concat
         .:/files/
         get-value:x:@strings.join
         .:/
      strings.replace:x:-
         .://
         .:/
      cql.execute:"insert into files (tenant, cloudlet, folder, filename, content) values (:tenant, :cloudlet, :folder, :filename, :content)"
         tenant:x:@.tenant
         cloudlet:x:@.cloudlet
         folder:x:@strings.replace
         filename:x:@.filename
         content:x:@io.file.load.binary

remove-nodes:x:../**/io.folder.list-recursively/*
remove-nodes:x:../**/io.file.list-recursively/*

What the above does is to "slurp up" all dynamic files you've got in your Magic installation and insert these into your "files" table. If you're using the default Docker images we publish for Magic, and you want to insert the files into a table such that they will be correctly resolved from your Docker container, you can set "tenant" to "magic" and "cloudlet" to "files". This allows you to create hundreds of Magic instances, load balance between these using Kubernetes, and have they all resolve towards the same "virtual file system".

When you have done the above, you'll have to reconfigure Magic to use your virtual file system, and restart your container. The configuration settings for doing this is as follows.

JSON
 
{
  "magic": {
    "io": {
      "file-service": "magic.data.cql.io.CqlFileService",
      "folder-service": "magic.data.cql.io.CqlFolderService",
      "stream-service": "magic.data.cql.io.CqlStreamService"
    }
  }
}

At this point you can restart Magic's container, and it will automagically use the files inside of your Scylla or Cassandra database. To create a table to use for logging you can use the following CQL.

CQL
 
create keyspace if not exists magic with
   replication = {
      'class': 'NetworkTopologyStrategy',
      'replication_factor': 5
   };

use magic;

create table if not exists log_entries(
   tenant text,
   cloudlet text,
   created timeuuid,
   type text,
   content text,
   exception text,
   primary key((tenant, cloudlet), created)) with clustering order by (created desc);

alter table log_entries with default_time_to_live = 604800;

Notice the time to live setting. This will ensure that log items are automatically deleted after 7 days, which is the equivalent of 604,800 seconds. Change this as you see fit. When you have created the above table you can configure Magic to use your CQL log implementation with the following addition to your "appsettings.json" file.

JSON
 
{
  "magic": {
    "logging": {
      "service": "magic.data.cql.logging.Logger"
    }
  }
}

Then restart your container, and Magic will automatically use your NoSQL database for logging. Notice both of the above changes requires you to allow your Docker containers to actually access your NoSQL database. Hence, you'll have to modify Magic's "docker-compose.yml" file to somehow access your NoSQL database, either by using the host network, or by exposing the relevant ports. This is true for both your NoSQL docker images if you're using Docker to create ScyllaDB or Cassandra instances, and your Magic backend Docker image. How to do this varies according to how you intend to run things, but you should be able to figure out things with the information specified here.

NoSQL Docker (software) Database Kubernetes File system

Opinions expressed by DZone contributors are their own.

Related

  • Manage Microservices With Docker Compose
  • Common Performance Management Mistakes
  • 7 Microservices Best Practices for Developers
  • The Importance of Persistent Storage in Kubernetes- OpenEBS

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!